|
48 | 48 | import android.app.StatsManager; |
49 | 49 | import android.app.UidObserver; |
50 | 50 | import android.content.BroadcastReceiver; |
| 51 | +import android.content.ContentResolver; |
51 | 52 | import android.content.Context; |
52 | 53 | import android.content.Intent; |
53 | 54 | import android.content.IntentFilter; |
|
60 | 61 | import android.content.res.Resources; |
61 | 62 | import android.content.res.TypedArray; |
62 | 63 | import android.content.res.XmlResourceParser; |
| 64 | +import android.database.ContentObserver; |
63 | 65 | import android.hardware.power.Mode; |
64 | 66 | import android.net.Uri; |
65 | 67 | import android.os.Binder; |
|
81 | 83 | import android.os.UserManager; |
82 | 84 | import android.provider.DeviceConfig; |
83 | 85 | import android.provider.DeviceConfig.Properties; |
| 86 | +import android.provider.Settings; |
84 | 87 | import android.text.TextUtils; |
85 | 88 | import android.util.ArrayMap; |
86 | 89 | import android.util.AtomicFile; |
@@ -1600,6 +1603,10 @@ public void onReceive(Context context, Intent intent) { |
1600 | 1603 | mGameDefaultFrameRateValue = (float) mSysProps.getInt( |
1601 | 1604 | PROPERTY_RO_SURFACEFLINGER_GAME_DEFAULT_FRAME_RATE, 60); |
1602 | 1605 | 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); |
1603 | 1610 | } |
1604 | 1611 |
|
1605 | 1612 | private void sendUserMessage(int userId, int what, String eventForLog, int delayMillis) { |
@@ -2372,4 +2379,41 @@ private void handleUidMovedOffTop(int uid) { |
2372 | 2379 | } |
2373 | 2380 | } |
2374 | 2381 | } |
| 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 | + |
2375 | 2419 | } |
0 commit comments