Schematize ADB system properties
Properties accessed across partitions are now schematized and will become APIs to make explicit interfaces among partitions. Bug: 117924132 Test: m -j Change-Id: Iec37f5f35b1452afdf7b15e9f31c4b4726127065
This commit is contained in:
@@ -22,6 +22,7 @@ import android.os.RemoteException;
|
|||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.sysprop.AdbProperties;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -39,9 +40,6 @@ public class ClearAdbKeysPreferenceController extends DeveloperOptionsPreference
|
|||||||
private static final String TAG = "ClearAdbPrefCtrl";
|
private static final String TAG = "ClearAdbPrefCtrl";
|
||||||
private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
|
private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String RO_ADB_SECURE_PROPERTY_KEY = "ro.adb.secure";
|
|
||||||
|
|
||||||
private final IAdbManager mAdbManager;
|
private final IAdbManager mAdbManager;
|
||||||
private final DevelopmentSettingsDashboardFragment mFragment;
|
private final DevelopmentSettingsDashboardFragment mFragment;
|
||||||
|
|
||||||
@@ -55,7 +53,7 @@ public class ClearAdbKeysPreferenceController extends DeveloperOptionsPreference
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return SystemProperties.getBoolean(RO_ADB_SECURE_PROPERTY_KEY, false /* default */);
|
return AdbProperties.secure().orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.development;
|
package com.android.settings.development;
|
||||||
|
|
||||||
import static com.android.settings.development.ClearAdbKeysPreferenceController
|
|
||||||
.RO_ADB_SECURE_PROPERTY_KEY;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -30,7 +27,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.debug.IAdbManager;
|
import android.debug.IAdbManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemProperties;
|
import android.sysprop.AdbProperties;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -83,21 +80,21 @@ public class ClearAdbKeysPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_roAdbSecureEnabled_shouldBeTrue() {
|
public void isAvailable_roAdbSecureEnabled_shouldBeTrue() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
|
AdbProperties.secure(true);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_roAdbSecureDisabled_shouldBeFalse() {
|
public void isAvailable_roAdbSecureDisabled_shouldBeFalse() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(false));
|
AdbProperties.secure(false);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_isNotAdminUser_preferenceShouldBeDisabled() {
|
public void displayPreference_isNotAdminUser_preferenceShouldBeDisabled() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
|
AdbProperties.secure(true);
|
||||||
doReturn(false).when(mController).isAdminUser();
|
doReturn(false).when(mController).isAdminUser();
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
@@ -108,7 +105,7 @@ public class ClearAdbKeysPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowClearAdbKeysWarningDialog.class)
|
@Config(shadows = ShadowClearAdbKeysWarningDialog.class)
|
||||||
public void handlePreferenceTreeClick_clearAdbKeysPreference_shouldShowWarningDialog() {
|
public void handlePreferenceTreeClick_clearAdbKeysPreference_shouldShowWarningDialog() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
|
AdbProperties.secure(true);
|
||||||
doReturn(true).when(mController).isAdminUser();
|
doReturn(true).when(mController).isAdminUser();
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
final String preferenceKey = mController.getPreferenceKey();
|
final String preferenceKey = mController.getPreferenceKey();
|
||||||
@@ -121,7 +118,7 @@ public class ClearAdbKeysPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick_notClearAdbKeysPreference_shouldReturnFalse() {
|
public void handlePreferenceTreeClick_notClearAdbKeysPreference_shouldReturnFalse() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
|
AdbProperties.secure(true);
|
||||||
doReturn(true).when(mController).isAdminUser();
|
doReturn(true).when(mController).isAdminUser();
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
when(mPreference.getKey()).thenReturn("Some random key!!!");
|
when(mPreference.getKey()).thenReturn("Some random key!!!");
|
||||||
@@ -132,7 +129,7 @@ public class ClearAdbKeysPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick_monkeyUser_shouldReturnFalse() {
|
public void handlePreferenceTreeClick_monkeyUser_shouldReturnFalse() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
|
AdbProperties.secure(true);
|
||||||
doReturn(true).when(mController).isAdminUser();
|
doReturn(true).when(mController).isAdminUser();
|
||||||
ShadowUtils.setIsUserAMonkey(true);
|
ShadowUtils.setIsUserAMonkey(true);
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
@@ -146,7 +143,7 @@ public class ClearAdbKeysPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onDeveloperOptionsSwitchEnabled_isAdminUser_shouldEnablePreference() {
|
public void onDeveloperOptionsSwitchEnabled_isAdminUser_shouldEnablePreference() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
|
AdbProperties.secure(true);
|
||||||
doReturn(true).when(mController).isAdminUser();
|
doReturn(true).when(mController).isAdminUser();
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
mController.onDeveloperOptionsSwitchEnabled();
|
mController.onDeveloperOptionsSwitchEnabled();
|
||||||
@@ -156,7 +153,7 @@ public class ClearAdbKeysPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onDeveloperOptionsSwitchEnabled_isNotAdminUser_shouldNotEnablePreference() {
|
public void onDeveloperOptionsSwitchEnabled_isNotAdminUser_shouldNotEnablePreference() {
|
||||||
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
|
AdbProperties.secure(true);
|
||||||
doReturn(false).when(mController).isAdminUser();
|
doReturn(false).when(mController).isAdminUser();
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
mController.onDeveloperOptionsSwitchEnabled();
|
mController.onDeveloperOptionsSwitchEnabled();
|
||||||
|
Reference in New Issue
Block a user