Skip to content

Commit db7e240

Browse files
Dhina17rmp22
authored andcommitted
GameManagerService: Set device_config property on behalf of GameSpace
GTS don't allow any app to have the android.permission.WRITE_DEVICE_CONFIG permission i.e we can't modify device_config property from our game space. So write the property to our custom Settings.Secure.GAME_OVERLAY. Then observe the value changes and set the property to the device_config from here. Since GameManagerService is a part of system_server, GTS will be happy. Change-Id: I0ebbcd6188411a583fa53904e6153482f342a03e Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent 2069166 commit db7e240

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

services/core/java/com/android/server/app/GameManagerService.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import android.app.StatsManager;
4949
import android.app.UidObserver;
5050
import android.content.BroadcastReceiver;
51+
import android.content.ContentResolver;
5152
import android.content.Context;
5253
import android.content.Intent;
5354
import android.content.IntentFilter;
@@ -60,6 +61,7 @@
6061
import android.content.res.Resources;
6162
import android.content.res.TypedArray;
6263
import android.content.res.XmlResourceParser;
64+
import android.database.ContentObserver;
6365
import android.hardware.power.Mode;
6466
import android.net.Uri;
6567
import android.os.Binder;
@@ -81,6 +83,7 @@
8183
import android.os.UserManager;
8284
import android.provider.DeviceConfig;
8385
import android.provider.DeviceConfig.Properties;
86+
import android.provider.Settings;
8487
import android.text.TextUtils;
8588
import android.util.ArrayMap;
8689
import android.util.AtomicFile;
@@ -1600,6 +1603,10 @@ public void onReceive(Context context, Intent intent) {
16001603
mGameDefaultFrameRateValue = (float) mSysProps.getInt(
16011604
PROPERTY_RO_SURFACEFLINGER_GAME_DEFAULT_FRAME_RATE, 60);
16021605
Slog.v(TAG, "Game Default Frame Rate : " + mGameDefaultFrameRateValue);
1606+
1607+
// Start to observe our Settings.Secure.GAME_OVERLAY
1608+
// after boot completed.
1609+
new SettingsObserver(mHandler);
16031610
}
16041611

16051612
private void sendUserMessage(int userId, int what, String eventForLog, int delayMillis) {
@@ -2372,4 +2379,41 @@ private void handleUidMovedOffTop(int uid) {
23722379
}
23732380
}
23742381
}
2382+
2383+
class SettingsObserver extends ContentObserver {
2384+
2385+
private final ContentResolver mContentResolver;
2386+
2387+
SettingsObserver(Handler handler) {
2388+
super(handler);
2389+
mContentResolver = mContext.getContentResolver();
2390+
mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
2391+
"game_overlay"), false, this,
2392+
UserHandle.USER_ALL);
2393+
}
2394+
2395+
@Override
2396+
public void onChange(boolean selfChange, Uri uri) {
2397+
String newValue = Settings.Secure.getString(mContentResolver,
2398+
"game_overlay");
2399+
// We write key and value of the device_config property as a single string
2400+
// from our GameSpace.
2401+
// ';;' is the separator betweeen key and value.
2402+
// Example: com.libremobileos.game;;mode=2,downscaleFactor=0.7:mode=3,downscaleFactor=0.8
2403+
// So split the key and value from the string
2404+
// and set the device_config propery.
2405+
String[] parsedValues = newValue.split(";;");
2406+
// Value should contain both package name and config.
2407+
// Otherwise don't do anything.
2408+
if (parsedValues.length < 2) return;
2409+
// We don't need to care about any format and all.
2410+
// It will be handled by the GamePackageConfiguration while
2411+
// parsing the device_config property.
2412+
String packageName = parsedValues[0];
2413+
String configValue = parsedValues[1];
2414+
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_GAME_OVERLAY,
2415+
packageName, configValue, false);
2416+
}
2417+
}
2418+
23752419
}

0 commit comments

Comments
 (0)