Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2153e5ea authored by Peiyong Lin's avatar Peiyong Lin Committed by Automerger Merge Worker
Browse files

Merge "Avoid print stack trace." into sc-dev am: 2104b875

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15191966

Change-Id: I6f66a556dbf5a7de6a162419b7e56108f95bb414
parents d690e0f3 2104b875
Loading
Loading
Loading
Loading
+48 −14
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import static com.android.server.wm.CompatModePackages.DOWNSCALE_90;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.app.ActivityManager;
import android.app.GameManager;
@@ -73,6 +74,7 @@ import com.android.internal.compat.CompatibilityOverrideConfig;
import com.android.internal.compat.IPlatformCompat;
import com.android.server.ServiceThread;
import com.android.server.SystemService;
import com.android.server.SystemService.TargetUser;

import java.io.FileDescriptor;
import java.util.List;
@@ -196,6 +198,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
                    final int userId = (int) msg.obj;
                    final String[] packageNames = getInstalledGamePackageNames(userId);
                    updateConfigsForUser(userId, packageNames);
                    break;
                }
            }
        }
@@ -212,7 +215,7 @@ public final class GameManagerService extends IGameManagerService.Stub {
        @Override
        public void onPropertiesChanged(Properties properties) {
            final String[] packageNames = properties.getKeyset().toArray(new String[0]);
            updateConfigsForUser(mContext.getUserId(), packageNames);
            updateConfigsForUser(ActivityManager.getCurrentUser(), packageNames);
        }

        @Override
@@ -496,6 +499,11 @@ public final class GameManagerService extends IGameManagerService.Stub {
        public void onUserStopping(@NonNull TargetUser user) {
            mService.onUserStopping(user.getUserIdentifier());
        }

        @Override
        public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) {
            mService.onUserSwitching(from, to.getUserIdentifier());
        }
    }

    private boolean isValidPackageName(String packageName, int userId) {
@@ -503,7 +511,6 @@ public final class GameManagerService extends IGameManagerService.Stub {
            return mPackageManager.getPackageUidAsUser(packageName, userId)
                    == Binder.getCallingUid();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }
@@ -567,7 +574,6 @@ public final class GameManagerService extends IGameManagerService.Stub {
                return GameManager.GAME_MODE_UNSUPPORTED;
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return GameManager.GAME_MODE_UNSUPPORTED;
        }

@@ -606,7 +612,6 @@ public final class GameManagerService extends IGameManagerService.Stub {
                return;
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return;
        }

@@ -639,15 +644,13 @@ public final class GameManagerService extends IGameManagerService.Stub {

    void onUserStarting(int userId) {
        synchronized (mLock) {
            if (mSettings.containsKey(userId)) {
                return;
            }

            if (!mSettings.containsKey(userId)) {
                GameManagerSettings userSettings =
                        new GameManagerSettings(Environment.getDataSystemDeDirectory(userId));
                mSettings.put(userId, userSettings);
                userSettings.readPersistentDataLocked();
            }
        }
        final Message msg = mHandler.obtainMessage(POPULATE_GAME_MODE_SETTINGS);
        msg.obj = userId;
        mHandler.sendMessage(msg);
@@ -664,6 +667,22 @@ public final class GameManagerService extends IGameManagerService.Stub {
        }
    }

    void onUserSwitching(TargetUser from, int toUserId) {
        if (from != null) {
            synchronized (mLock) {
                final int fromUserId = from.getUserIdentifier();
                if (mSettings.containsKey(fromUserId)) {
                    final Message msg = mHandler.obtainMessage(REMOVE_SETTINGS);
                    msg.obj = fromUserId;
                    mHandler.sendMessage(msg);
                }
            }
        }
        final Message msg = mHandler.obtainMessage(POPULATE_GAME_MODE_SETTINGS);
        msg.obj = toUserId;
        mHandler.sendMessage(msg);
    }

    /**
     * @hide
     */
@@ -856,11 +875,25 @@ public final class GameManagerService extends IGameManagerService.Stub {
            public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
                final Uri data = intent.getData();
                try {
                    final int userId = getSendingUserId();
                    if (userId != ActivityManager.getCurrentUser()) {
                        return;
                    }
                    final String packageName = data.getSchemeSpecificPart();
                    try {
                        final ApplicationInfo applicationInfo = mPackageManager
                                .getApplicationInfoAsUser(
                                        packageName, PackageManager.MATCH_ALL, userId);
                        if (applicationInfo.category != ApplicationInfo.CATEGORY_GAME) {
                            return;
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                        // Ignore the exception.
                    }
                    switch (intent.getAction()) {
                        case ACTION_PACKAGE_ADDED:
                        case ACTION_PACKAGE_CHANGED:
                            updateConfigsForUser(mContext.getUserId(), packageName);
                            updateConfigsForUser(userId, packageName);
                            break;
                        case ACTION_PACKAGE_REMOVED:
                            disableCompatScale(packageName);
@@ -873,11 +906,12 @@ public final class GameManagerService extends IGameManagerService.Stub {
                            break;
                    }
                } catch (NullPointerException e) {
                    Slog.e(TAG, "Failed to get package name for new package", e);
                    Slog.e(TAG, "Failed to get package name for new package");
                }
            }
        };
        mContext.registerReceiver(packageReceiver, packageFilter);
        mContext.registerReceiverForAllUsers(packageReceiver, packageFilter,
                /* broadcastPermission= */ null, /* scheduler= */ null);
    }

    private void registerDeviceConfigListener() {