Fix a strict mode violation in SystemUpdatePrefController
Change-Id: I4770b878b6f69318f08f8974c5c4d2690c5611d4 Merged-In: I4770b878b6f69318f08f8974c5c4d2690c5611d4 Fixes: 78626509 Test: robotests
This commit is contained in:
@@ -47,7 +47,9 @@ public interface DeviceIndexFeatureProvider {
|
||||
List<String> keywords);
|
||||
|
||||
default void updateIndex(Context context, boolean force) {
|
||||
if (!isIndexingEnabled()) return;
|
||||
if (!isIndexingEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!force && Objects.equals(
|
||||
Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION)) {
|
||||
@@ -55,9 +57,9 @@ public interface DeviceIndexFeatureProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentName jobComponent = new ComponentName(context.getPackageName(),
|
||||
final ComponentName jobComponent = new ComponentName(context.getPackageName(),
|
||||
DeviceIndexUpdateJobService.class.getName());
|
||||
int jobId = context.getResources().getInteger(R.integer.device_index_update);
|
||||
final int jobId = context.getResources().getInteger(R.integer.device_index_update);
|
||||
// Schedule a job so that we know it'll be able to complete, but try to run as
|
||||
// soon as possible.
|
||||
context.getSystemService(JobScheduler.class).schedule(
|
||||
|
@@ -23,6 +23,7 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.Utils;
|
||||
@@ -32,10 +33,14 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
public class VisiblePatternProfilePreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnResume {
|
||||
|
||||
private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
|
||||
private static final String TAG = "VisPtnProfPrefCtrl";
|
||||
|
||||
private final LockPatternUtils mLockPatternUtils;
|
||||
private final UserManager mUm;
|
||||
@@ -45,7 +50,7 @@ public class VisiblePatternProfilePreferenceController extends TogglePreferenceC
|
||||
private Preference mPreference;
|
||||
|
||||
public VisiblePatternProfilePreferenceController(Context context) {
|
||||
this(context, null /* lifecycle */);
|
||||
this(context, null /* lifecycle */);
|
||||
}
|
||||
|
||||
// TODO (b/73074893) Replace this constructor without Lifecycle using setter method instead.
|
||||
@@ -63,12 +68,25 @@ public class VisiblePatternProfilePreferenceController extends TogglePreferenceC
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mLockPatternUtils.isSecure(mProfileChallengeUserId)
|
||||
&& mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
|
||||
== PASSWORD_QUALITY_SOMETHING) {
|
||||
return AVAILABLE;
|
||||
final FutureTask<Integer> futureTask = new FutureTask<>(
|
||||
// Put the API call in a future to avoid StrictMode violation.
|
||||
() -> {
|
||||
final boolean isSecure = mLockPatternUtils.isSecure(mProfileChallengeUserId);
|
||||
final boolean hasPassword = mLockPatternUtils
|
||||
.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
|
||||
== PASSWORD_QUALITY_SOMETHING;
|
||||
if (isSecure && hasPassword) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
return DISABLED_FOR_USER;
|
||||
});
|
||||
try {
|
||||
futureTask.run();
|
||||
return futureTask.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
Log.w(TAG, "Error getting lock pattern state.");
|
||||
return DISABLED_FOR_USER;
|
||||
}
|
||||
return DISABLED_FOR_USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -26,7 +26,6 @@ import android.content.Intent;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
@@ -155,11 +154,6 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
|
||||
@Override
|
||||
public Slice onBindSlice(Uri sliceUri) {
|
||||
// TODO: Remove this when all slices are not breaking strict mode
|
||||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
||||
.permitAll()
|
||||
.build());
|
||||
|
||||
String path = sliceUri.getPath();
|
||||
// If adding a new Slice, do not directly match Slice URIs.
|
||||
// Use {@link SlicesDatabaseAccessor}.
|
||||
|
@@ -35,6 +35,9 @@ import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
public class SystemUpdatePreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "SysUpdatePrefContr";
|
||||
@@ -84,9 +87,19 @@ public class SystemUpdatePreferenceController extends BasePreferenceController {
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final Bundle updateInfo = mUpdateManager.retrieveSystemUpdateInfo();
|
||||
CharSequence summary = mContext.getString(R.string.android_version_summary,
|
||||
Build.VERSION.RELEASE);
|
||||
final FutureTask<Bundle> bundleFutureTask = new FutureTask<>(
|
||||
// Put the API call in a future to avoid StrictMode violation.
|
||||
() -> mUpdateManager.retrieveSystemUpdateInfo());
|
||||
final Bundle updateInfo;
|
||||
try {
|
||||
bundleFutureTask.run();
|
||||
updateInfo = bundleFutureTask.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
Log.w(TAG, "Error getting system update info.");
|
||||
return summary;
|
||||
}
|
||||
switch (updateInfo.getInt(SystemUpdateManager.KEY_STATUS)) {
|
||||
case SystemUpdateManager.STATUS_WAITING_DOWNLOAD:
|
||||
case SystemUpdateManager.STATUS_IN_PROGRESS:
|
||||
|
@@ -28,6 +28,7 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
@@ -53,16 +54,17 @@ import androidx.slice.Slice;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SettingsSliceProviderTest {
|
||||
|
||||
private final String KEY = "KEY";
|
||||
private final String INTENT_PATH = SettingsSlicesContract.PATH_SETTING_INTENT + "/" + KEY;
|
||||
private final String ACTION_PATH = SettingsSlicesContract.PATH_SETTING_ACTION + "/" + KEY;
|
||||
private final String TITLE = "title";
|
||||
private final String SUMMARY = "summary";
|
||||
private final String SCREEN_TITLE = "screen title";
|
||||
private final String FRAGMENT_NAME = "fragment name";
|
||||
private final int ICON = 1234; // I declare a thumb war
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private final String PREF_CONTROLLER = FakeToggleController.class.getName();
|
||||
private static final String KEY = "KEY";
|
||||
private static final String INTENT_PATH =
|
||||
SettingsSlicesContract.PATH_SETTING_INTENT + "/" + KEY;
|
||||
private static final String TITLE = "title";
|
||||
private static final String SUMMARY = "summary";
|
||||
private static final String SCREEN_TITLE = "screen title";
|
||||
private static final String FRAGMENT_NAME = "fragment name";
|
||||
private static final int ICON = 1234; // I declare a thumb war
|
||||
private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private static final String PREF_CONTROLLER = FakeToggleController.class.getName();
|
||||
|
||||
private Context mContext;
|
||||
private SettingsSliceProvider mProvider;
|
||||
private SQLiteDatabase mDb;
|
||||
@@ -147,6 +149,18 @@ public class SettingsSliceProviderTest {
|
||||
assertThat(cachedData).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindSlice_shouldNotOverrideStrictMode() {
|
||||
final StrictMode.ThreadPolicy oldThreadPolicy = StrictMode.getThreadPolicy();
|
||||
SliceData data = getDummyData();
|
||||
mProvider.mSliceWeakDataCache.put(data.getUri(), data);
|
||||
mProvider.onBindSlice(data.getUri());
|
||||
|
||||
final StrictMode.ThreadPolicy newThreadPolicy = StrictMode.getThreadPolicy();
|
||||
|
||||
assertThat(newThreadPolicy.toString()).isEqualTo(oldThreadPolicy.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSlice_cachedEntryRemovedOnUnpin() {
|
||||
SliceData data = getDummyData();
|
||||
|
Reference in New Issue
Block a user