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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
/*
* Copyright (c) 2012 - 2014 NVIDIA Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Class structure based upon Camera in Camera.java:
* Copyright (C) 2009 The Android Open Source Project
*/
package com.nvidia;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.util.Log;
import com.nvidia.profilemanager.NvAppProfileSettingId;
/**
* @hide
*/
public class NvAppProfileService {
private static final String TAG = "NvAppProfileService";
private static final String APP_START_ACTION =
"com.nvidia.NvAppProfileService.action.APP_START";
private static final String APP_START_TARGET_PACKAGE = "com.nvidia.peripheralservice";
private static final String FEATURE_POWER_BUDGET_CONTROL =
"nvidia.feature.power_budget_control";
private static final String FEATURE_FAN_ON_DEVICE = "nvidia.feature.fan_on_device";
private final NvAppProfiles mAppProfile;
private final NvWhitelistService mWhitelistService;
private final Context mContext;
private boolean mInitialisedAppProfiles = false;
private boolean mFanCapEnabled = false;
private boolean mPbcEnabled = false;
public NvAppProfileService(Context context) {
Context appContext = context.getApplicationContext();
if (appContext == null) {
mContext = context;
} else {
mContext = appContext;
}
mAppProfile = new NvAppProfiles(mContext);
mWhitelistService = new NvWhitelistService(mContext);
}
private static String getPackageName(String appName) {
int index = appName.indexOf('/');
if (index < 0) {
Log.e(TAG, "appName does not contain '/'. " +
"The packageName cannot be extracted from appName!");
return null;
}
return appName.substring(0, index);
}
/*
* These are functions that depend on NvAppProfiles and may or may not
* be supported for certain platforms. In the latter case, these methods
* should return -1.
*/
public boolean getAppProfileFRCEnable(String packageName) {
return packageName != null && mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.VIDEO_FRC_ENABLE) == 1;
}
public boolean getAppProfileCreateSecureDecoder(String packageName) {
return packageName != null && mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.VIDEO_SECURE_DECODE) == 1;
}
public boolean getAppProfileTSFilterEnable(String packageName) {
return packageName != null && mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.VIDEO_TS_FILTERING) == 1;
}
public boolean getAppProfileMediaEnableMsdHal(String packageName) {
return packageName != null && this.mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.MEDIA_ENABLE_MSD_HAL) == 1;
}
public boolean getAppProfileNvidiaCertification(String packageName) {
return packageName != null && mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.NVIDIA_VIDEO_CERTIFICATION_ENABLED) == 1;
}
public String customizeAppBanner(String packageName) {
if (packageName == null) return null;
final String bannerName = mAppProfile.getApplicationProfileString(packageName,
NvAppProfileSettingId.WHITELIST_CUSTOMIZE_BANNER);
if (bannerName != null) return bannerName;
return mWhitelistService.getBannerName(packageName);
}
public Drawable getBannerDrawable(String packageName) {
final String bannerName = customizeAppBanner(packageName);
if (bannerName == null || bannerName.length() == 0) {
return null;
}
final Resources systemResources = mContext.getResources().getSystem();
final int drawableResourceId = systemResources.getIdentifier(bannerName,
"drawable", "android");
if (drawableResourceId == 0) return null;
return systemResources.getDrawable(drawableResourceId);
}
public NvWhitelistService getWhitelistService() {
return mWhitelistService;
}
public boolean getAppProfileDisableApp(String packageName) {
return packageName != null && mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.DISABLE_APP) == 1;
}
private int getAppProfileCpuScalingMinFreq(String packageName) {
return mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.SCALING_MIN_FREQ);
}
private int getAppProfileCpuCoreBias(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.CORE_BIAS);
}
private int getAppProfileGpuScaling(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.GPU_SCALING);
}
private int getAppProfileCpuMaxNormalFreq(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.CPU_FREQ_BIAS);
}
private int getAppProfileCpuMaxNormalFreqPercent(String packageName) {
return mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.MAX_CPU_FREQ_PCT);
}
private int getAppProfileCpuMinCore(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.MIN_CPU_CORES);
}
private int getAppProfileCpuMaxCore(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.MAX_CPU_CORES);
}
private int getAppProfileGpuCbusCapLevel(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.GPU_CORE_CAP);
}
private int getAppProfileEdpMode(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.EDP_MODE);
}
private int getAppProfilePbcPwr(String packageName) {
if (!mPbcEnabled) return -1;
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.PBC_PWR_LIMIT);
}
private int getAppProfileFanCap(String packageName) {
if (!mFanCapEnabled) return -1;
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.FAN_PWM_CAP);
}
private int getAppProfileVoltTempMode(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.VOLT_TEMP_MODE);
}
private int getAppProfileAggresivePrismEnable(String packageName) {
return mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.AGGRESSIVE_PRISM_ENABLE);
}
private int getAppProfileDevicePowerMode(String packageName) {
return mAppProfile.getApplicationProfile(packageName,
NvAppProfileSettingId.SYSTEM_POWER_MODE);
}
public String getAppProfileRegionEnableList(String packageName) {
return mAppProfile.getApplicationProfileString(packageName,
NvAppProfileSettingId.SET_REGION_LIST);
}
public int getAppProfileNvidiaBBCApps(String packageName) {
return mAppProfile.getApplicationProfile(packageName, NvAppProfileSettingId.BBC_APPS);
}
private int retrievePowerMode() {
final String powerMode = SystemProperties.get(NvConstants.NvPowerModeProperty);
if (powerMode != null) {
try {
return Integer.parseInt(powerMode);
} catch (NumberFormatException ex) {
// Fallthrough to error case
}
}
return -1;
}
/**
* Interface for the caller
*/
public void setAppProfile(String packageName) {
// Greedy initialization of App Profiles
if (!mInitialisedAppProfiles) {
PackageManager pm = mContext.getPackageManager();
mPbcEnabled = pm.hasSystemFeature(FEATURE_POWER_BUDGET_CONTROL);
mFanCapEnabled = pm.hasSystemFeature(FEATURE_FAN_ON_DEVICE);
Log.w(TAG, "Enabled");
mInitialisedAppProfiles = true;
}
mAppProfile.powerHint(packageName);
Intent intent = new Intent(APP_START_ACTION);
intent.setPackage(APP_START_TARGET_PACKAGE);
intent.putExtra("AppStartId", packageName);
mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT,
"nvidia.permission.READ_APP_START_INFO");
}
}
|