Merge changes I36c6ef4b,I3c31394e
* changes: Allow UsbDeviceManager to start adbd again. Remove key from adb_keys if user forgets the key.
This commit is contained in:
@@ -53,4 +53,14 @@ public abstract class AdbManagerInternal {
|
|||||||
* Returns the file that contains all of the ADB keys and their last used time.
|
* Returns the file that contains all of the ADB keys and their last used time.
|
||||||
*/
|
*/
|
||||||
public abstract File getAdbTempKeysFile();
|
public abstract File getAdbTempKeysFile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts adbd for a transport.
|
||||||
|
*/
|
||||||
|
public abstract void startAdbdForTransport(byte transportType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops adbd for a transport.
|
||||||
|
*/
|
||||||
|
public abstract void stopAdbdForTransport(byte transportType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1849,6 +1849,7 @@ public class AdbDebuggingManager {
|
|||||||
public void removeKey(String key) {
|
public void removeKey(String key) {
|
||||||
if (mKeyMap.containsKey(key)) {
|
if (mKeyMap.containsKey(key)) {
|
||||||
mKeyMap.remove(key);
|
mKeyMap.remove(key);
|
||||||
|
writeKeys(mKeyMap.keySet());
|
||||||
sendPersistKeyStoreMessage();
|
sendPersistKeyStoreMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,18 @@ public class AdbService extends IAdbManager.Stub {
|
|||||||
public File getAdbTempKeysFile() {
|
public File getAdbTempKeysFile() {
|
||||||
return mDebuggingManager.getAdbTempKeysFile();
|
return mDebuggingManager.getAdbTempKeysFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startAdbdForTransport(byte transportType) {
|
||||||
|
FgThread.getHandler().sendMessage(obtainMessage(
|
||||||
|
AdbService::setAdbdEnabledForTransport, AdbService.this, true, transportType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopAdbdForTransport(byte transportType) {
|
||||||
|
FgThread.getHandler().sendMessage(obtainMessage(
|
||||||
|
AdbService::setAdbdEnabledForTransport, AdbService.this, false, transportType));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAdbState() {
|
private void initAdbState() {
|
||||||
@@ -437,6 +449,19 @@ public class AdbService extends IAdbManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAdbdEnabledForTransport(boolean enable, byte transportType) {
|
||||||
|
if (transportType == AdbTransportType.USB) {
|
||||||
|
mIsAdbUsbEnabled = enable;
|
||||||
|
} else if (transportType == AdbTransportType.WIFI) {
|
||||||
|
mIsAdbWifiEnabled = enable;
|
||||||
|
}
|
||||||
|
if (enable) {
|
||||||
|
startAdbd();
|
||||||
|
} else {
|
||||||
|
stopAdbd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setAdbEnabled(boolean enable, byte transportType) {
|
private void setAdbEnabled(boolean enable, byte transportType) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "setAdbEnabled(" + enable + "), mIsAdbUsbEnabled=" + mIsAdbUsbEnabled
|
Slog.d(TAG, "setAdbEnabled(" + enable + "), mIsAdbUsbEnabled=" + mIsAdbUsbEnabled
|
||||||
|
|||||||
@@ -672,6 +672,31 @@ public final class AdbDebuggingManagerTest {
|
|||||||
connectionTime2, mKeyStore.getLastConnectionTime(TEST_KEY_2));
|
connectionTime2, mKeyStore.getLastConnectionTime(TEST_KEY_2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdbKeyStore_removeKey() throws Exception {
|
||||||
|
// Accept the test key with the 'Always allow' option selected.
|
||||||
|
runAdbTest(TEST_KEY_1, true, true, false);
|
||||||
|
runAdbTest(TEST_KEY_2, true, true, false);
|
||||||
|
|
||||||
|
// Set the connection time to 0 to restore the original behavior.
|
||||||
|
setAllowedConnectionTime(0);
|
||||||
|
|
||||||
|
// Verify that the key is in the adb_keys file to ensure subsequent connections are
|
||||||
|
// automatically allowed by adbd.
|
||||||
|
persistKeyStore();
|
||||||
|
assertTrue("The key was not in the adb_keys file after persisting the keystore",
|
||||||
|
isKeyInFile(TEST_KEY_1, mAdbKeyFile));
|
||||||
|
assertTrue("The key was not in the adb_keys file after persisting the keystore",
|
||||||
|
isKeyInFile(TEST_KEY_2, mAdbKeyFile));
|
||||||
|
|
||||||
|
// Now remove one of the keys and make sure the other key is still there
|
||||||
|
mKeyStore.removeKey(TEST_KEY_1);
|
||||||
|
assertFalse("The key was still in the adb_keys file after removing the key",
|
||||||
|
isKeyInFile(TEST_KEY_1, mAdbKeyFile));
|
||||||
|
assertTrue("The key was not in the adb_keys file after removing a different key",
|
||||||
|
isKeyInFile(TEST_KEY_2, mAdbKeyFile));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs an adb test with the provided configuration.
|
* Runs an adb test with the provided configuration.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1898,7 +1898,19 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Adbd will be started by AdbService once Global.ADB_ENABLED is set.
|
if ((config & UsbManager.FUNCTION_ADB) != 0) {
|
||||||
|
/**
|
||||||
|
* Start adbd if ADB function is included in the configuration.
|
||||||
|
*/
|
||||||
|
LocalServices.getService(AdbManagerInternal.class)
|
||||||
|
.startAdbdForTransport(AdbTransportType.USB);
|
||||||
|
} else {
|
||||||
|
/**
|
||||||
|
* Stop adbd otherwise
|
||||||
|
*/
|
||||||
|
LocalServices.getService(AdbManagerInternal.class)
|
||||||
|
.stopAdbdForTransport(AdbTransportType.USB);
|
||||||
|
}
|
||||||
UsbGadgetCallback usbGadgetCallback = new UsbGadgetCallback(mCurrentRequest,
|
UsbGadgetCallback usbGadgetCallback = new UsbGadgetCallback(mCurrentRequest,
|
||||||
config, chargingFunctions);
|
config, chargingFunctions);
|
||||||
mGadgetProxy.setCurrentUsbFunctions(config, usbGadgetCallback,
|
mGadgetProxy.setCurrentUsbFunctions(config, usbGadgetCallback,
|
||||||
|
|||||||
Reference in New Issue
Block a user