Merge "Add a mechanism to disable the incompatible charger warning" into udc-dev
This commit is contained in:
@@ -67,6 +67,10 @@ public class Utils {
|
|||||||
static final String STORAGE_MANAGER_ENABLED_PROPERTY =
|
static final String STORAGE_MANAGER_ENABLED_PROPERTY =
|
||||||
"ro.storage_manager.enabled";
|
"ro.storage_manager.enabled";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String INCOMPATIBLE_CHARGER_WARNING_DISABLED =
|
||||||
|
"incompatible_charger_warning_disabled";
|
||||||
|
|
||||||
private static Signature[] sSystemSignature;
|
private static Signature[] sSystemSignature;
|
||||||
private static String sPermissionControllerPackageName;
|
private static String sPermissionControllerPackageName;
|
||||||
private static String sServicesSystemSharedLibPackageName;
|
private static String sServicesSystemSharedLibPackageName;
|
||||||
@@ -652,6 +656,19 @@ public class Utils {
|
|||||||
|
|
||||||
/** Whether there is any incompatible chargers in the current UsbPort? */
|
/** Whether there is any incompatible chargers in the current UsbPort? */
|
||||||
public static boolean containsIncompatibleChargers(Context context, String tag) {
|
public static boolean containsIncompatibleChargers(Context context, String tag) {
|
||||||
|
// Avoid the caller doesn't have permission to read the "Settings.Secure" data.
|
||||||
|
try {
|
||||||
|
// Whether the incompatible charger warning is disabled or not
|
||||||
|
if (Settings.Secure.getInt(context.getContentResolver(),
|
||||||
|
INCOMPATIBLE_CHARGER_WARNING_DISABLED, 0) == 1) {
|
||||||
|
Log.d(tag, "containsIncompatibleChargers: disabled");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(tag, "containsIncompatibleChargers()", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final List<UsbPort> usbPortList =
|
final List<UsbPort> usbPortList =
|
||||||
context.getSystemService(UsbManager.class).getPorts();
|
context.getSystemService(UsbManager.class).getPorts();
|
||||||
if (usbPortList == null || usbPortList.isEmpty()) {
|
if (usbPortList == null || usbPortList.isEmpty()) {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import android.telephony.NetworkRegistrationInfo;
|
|||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -65,6 +66,7 @@ import java.util.Map;
|
|||||||
@Config(shadows = {UtilsTest.ShadowSecure.class, UtilsTest.ShadowLocationManager.class})
|
@Config(shadows = {UtilsTest.ShadowSecure.class, UtilsTest.ShadowLocationManager.class})
|
||||||
public class UtilsTest {
|
public class UtilsTest {
|
||||||
private static final double[] TEST_PERCENTAGES = {0, 0.4, 0.5, 0.6, 49, 49.3, 49.8, 50, 100};
|
private static final double[] TEST_PERCENTAGES = {0, 0.4, 0.5, 0.6, 49, 49.3, 49.8, 50, 100};
|
||||||
|
private static final String TAG = "UtilsTest";
|
||||||
private static final String PERCENTAGE_0 = "0%";
|
private static final String PERCENTAGE_0 = "0%";
|
||||||
private static final String PERCENTAGE_1 = "1%";
|
private static final String PERCENTAGE_1 = "1%";
|
||||||
private static final String PERCENTAGE_49 = "49%";
|
private static final String PERCENTAGE_49 = "49%";
|
||||||
@@ -96,6 +98,12 @@ public class UtilsTest {
|
|||||||
mAudioManager = mContext.getSystemService(AudioManager.class);
|
mAudioManager = mContext.getSystemService(AudioManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void reset() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Utils.INCOMPATIBLE_CHARGER_WARNING_DISABLED, 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateLocationEnabled() {
|
public void testUpdateLocationEnabled() {
|
||||||
int currentUserId = ActivityManager.getCurrentUser();
|
int currentUserId = ActivityManager.getCurrentUser();
|
||||||
@@ -427,13 +435,13 @@ public class UtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void containsIncompatibleChargers_nullPorts_returnFalse() {
|
public void containsIncompatibleChargers_nullPorts_returnFalse() {
|
||||||
when(mUsbManager.getPorts()).thenReturn(null);
|
when(mUsbManager.getPorts()).thenReturn(null);
|
||||||
assertThat(Utils.containsIncompatibleChargers(mContext, "tag")).isFalse();
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void containsIncompatibleChargers_emptyPorts_returnFalse() {
|
public void containsIncompatibleChargers_emptyPorts_returnFalse() {
|
||||||
when(mUsbManager.getPorts()).thenReturn(new ArrayList<>());
|
when(mUsbManager.getPorts()).thenReturn(new ArrayList<>());
|
||||||
assertThat(Utils.containsIncompatibleChargers(mContext, "tag")).isFalse();
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -443,13 +451,13 @@ public class UtilsTest {
|
|||||||
when(mUsbManager.getPorts()).thenReturn(usbPorts);
|
when(mUsbManager.getPorts()).thenReturn(usbPorts);
|
||||||
when(mUsbPort.getStatus()).thenReturn(null);
|
when(mUsbPort.getStatus()).thenReturn(null);
|
||||||
|
|
||||||
assertThat(Utils.containsIncompatibleChargers(mContext, "tag")).isFalse();
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void containsIncompatibleChargers_returnTrue() {
|
public void containsIncompatibleChargers_returnTrue() {
|
||||||
setupIncompatibleCharging();
|
setupIncompatibleCharging();
|
||||||
assertThat(Utils.containsIncompatibleChargers(mContext, "tag")).isTrue();
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -457,7 +465,7 @@ public class UtilsTest {
|
|||||||
setupIncompatibleCharging();
|
setupIncompatibleCharging();
|
||||||
when(mUsbPortStatus.getComplianceWarnings()).thenReturn(new int[1]);
|
when(mUsbPortStatus.getComplianceWarnings()).thenReturn(new int[1]);
|
||||||
|
|
||||||
assertThat(Utils.containsIncompatibleChargers(mContext, "tag")).isFalse();
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -465,7 +473,7 @@ public class UtilsTest {
|
|||||||
setupIncompatibleCharging();
|
setupIncompatibleCharging();
|
||||||
when(mUsbPort.supportsComplianceWarnings()).thenReturn(false);
|
when(mUsbPort.supportsComplianceWarnings()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(Utils.containsIncompatibleChargers(mContext, "tag")).isFalse();
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -473,7 +481,16 @@ public class UtilsTest {
|
|||||||
setupIncompatibleCharging();
|
setupIncompatibleCharging();
|
||||||
when(mUsbPortStatus.isConnected()).thenReturn(false);
|
when(mUsbPortStatus.isConnected()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(Utils.containsIncompatibleChargers(mContext, "tag")).isFalse();
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void containsIncompatibleChargers_disableWarning_returnFalse() {
|
||||||
|
setupIncompatibleCharging();
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Utils.INCOMPATIBLE_CHARGER_WARNING_DISABLED, 1);
|
||||||
|
|
||||||
|
assertThat(Utils.containsIncompatibleChargers(mContext, TAG)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupIncompatibleCharging() {
|
private void setupIncompatibleCharging() {
|
||||||
|
|||||||
Reference in New Issue
Block a user