1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
package com.nvidia;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import com.nvidia.NvCPLSvc.INvCPLRemoteService;
public class NvAppProfiles {
/**
* Unique name used for NvCPLSvc to whitelist this class
*/
static final String NV_APP_PROFILES_NAME = "Frameworks_NvAppProfiles";
static final boolean DEBUG = false;
private static final String TAG = "NvAppProfiles";
private final Context mContext;
private INvCPLRemoteService mNvCPLSvc = null;
private IBinder mNvCPLSvcBinder = null;
/**
* Callback class given by the NvCPLService
*/
public NvAppProfiles(Context context) {
mContext = context;
}
public int getApplicationProfile(String packageName, int settingId) {
getNvCPLService();
if (mNvCPLSvc != null) {
try {
return mNvCPLSvc.getAppProfileSettingInt(packageName, settingId);
} catch (RemoteException ex) {
Log.w(TAG, "Failed to retrieve profile setting. Error=" + ex.getMessage());
}
}
return -1;
}
public String getApplicationProfileString(String packageName, int settingId) {
getNvCPLService();
if (mNvCPLSvc != null) {
try {
return mNvCPLSvc.getAppProfileSettingString(packageName, settingId);
} catch (RemoteException ex) {
Log.w(TAG, "Failed to retrieve profile setting. Error=" + ex.getMessage());
}
}
return null;
}
public void setPowerMode(int index) {
if (DEBUG) Log.w(TAG, "Setting power mode: " + String.valueOf(index));
Intent intent = new Intent();
intent.setClassName(NvConstants.NvCPLSvc, NvConstants.NvCPLService);
intent.putExtra(NvConstants.NvOrigin, 1);
intent.putExtra(NvConstants.NvPowerMode , String.valueOf(index));
handleIntent(intent);
}
public void powerHint(String packageName) {
getNvCPLService();
if (mNvCPLSvc != null) {
try {
mNvCPLSvc.powerHint(packageName);
} catch (RemoteException ex) {
Log.w(TAG, "Failed to send power hint. Error=" + ex.getMessage());
}
}
}
public void handleIntent(Intent intent) {
getNvCPLService();
if (mNvCPLSvc != null) {
try {
mNvCPLSvc.handleIntent(intent);
} catch (RemoteException ex) {
Log.w(TAG, "Failed to handle intent. Error=" + ex.getMessage());
}
}
}
private void getNvCPLService() {
if (mNvCPLSvc == null || mNvCPLSvcBinder == null || !mNvCPLSvcBinder.isBinderAlive()) {
mNvCPLSvcBinder = ServiceManager.getService("nvcpl");
mNvCPLSvc = INvCPLRemoteService.Stub.asInterface(mNvCPLSvcBinder);
}
}
}
|