Migrate to get{Int,String}ForUser

Reported by the lint CallingSettingsNonUserGetterMethodsDetector.
It is recommended to use the *ForUser variant of these functions to
avoid passing the incorrect user id.

Test: m
Bug: 228774926
Fix: 237603566
Change-Id: I2543be4737a30222284ee75c709419da0d409667
Merged-In: I2543be4737a30222284ee75c709419da0d409667
(cherry picked from commit 5731002fd8)
This commit is contained in:
Thiébaud Weksteen
2022-05-02 13:45:40 +10:00
committed by Sam Dubey
parent 5583658286
commit 31a7beb214
4 changed files with 17 additions and 9 deletions

View File

@@ -8183,8 +8183,8 @@ public class ActivityManagerService extends IActivityManager.Stub
// do this when the system user is not setup since the setup wizard should be the one
// to handle home activity in this case.
if (UserManager.isSplitSystemUser() &&
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE, 0) != 0
Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE, 0, currentUserId) != 0
|| SystemProperties.getBoolean(SYSTEM_USER_HOME_NEEDED, false)) {
t.traceBegin("enableHomeActivity");
ComponentName cName = new ComponentName(mContext, SystemUserHomeActivity.class);

View File

@@ -16,6 +16,7 @@
package com.android.server.am;
import android.app.ActivityThread;
import android.content.ContentResolver;
import android.provider.Settings;
import android.util.ArrayMap;
@@ -53,9 +54,12 @@ public class ActivityManagerUtils {
static int getAndroidIdHash() {
// No synchronization is required. Double-initialization is fine here.
if (sAndroidIdHash == null) {
final String androidId = Settings.Secure.getString(
ActivityThread.currentApplication().getContentResolver(),
Settings.Secure.ANDROID_ID);
final ContentResolver resolver = ActivityThread.currentApplication()
.getContentResolver();
final String androidId = Settings.Secure.getStringForUser(
resolver,
Settings.Secure.ANDROID_ID,
resolver.getUserId());
sAndroidIdHash = getUnsignedHashUnCached(
sInjectedAndroidId != null ? sInjectedAndroidId : androidId);
}

View File

@@ -28,6 +28,7 @@ import android.app.AnrController;
import android.app.ApplicationErrorReport;
import android.app.ApplicationExitInfo;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.IncrementalStatesInfo;
@@ -626,8 +627,11 @@ class ProcessErrorStateRecord {
}
private boolean getShowBackground() {
return Settings.Secure.getInt(mService.mContext.getContentResolver(),
Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
final ContentResolver resolver = mService.mContext.getContentResolver();
return Settings.Secure.getIntForUser(resolver,
Settings.Secure.ANR_SHOW_BACKGROUND,
0,
resolver.getUserId()) != 0;
}
/**

View File

@@ -218,8 +218,8 @@ public class ActivityStartController {
vers = ri.activityInfo.applicationInfo.metaData.getString(
Intent.METADATA_SETUP_VERSION);
}
String lastVers = Settings.Secure.getString(
resolver, Settings.Secure.LAST_SETUP_SHOWN);
String lastVers = Settings.Secure.getStringForUser(
resolver, Settings.Secure.LAST_SETUP_SHOWN, resolver.getUserId());
if (vers != null && !vers.equals(lastVers)) {
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(