Skip to content

Commit 44d4eea

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "Use default encryption password if an accessibility service is enabled." into lmp-dev
2 parents 415393f + 16e4a1a commit 44d4eea

4 files changed

Lines changed: 102 additions & 2 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.view;
18+
19+
/**
20+
* Accessibility manager local system service interface.
21+
*
22+
* @hide Only for use within the system server.
23+
*/
24+
public abstract class AccessibilityManagerInternal {
25+
26+
/**
27+
* Queries if the accessibility manager service permits setting
28+
* a non-default encryption password.
29+
*/
30+
public abstract boolean isNonDefaultEncryptionPasswordAllowed();
31+
}

core/java/com/android/internal/widget/LockPatternUtils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,30 @@ public void saveLockPassword(String password, int quality, boolean isFallback, i
877877
}
878878
}
879879

880+
/**
881+
* Gets whether the device is encrypted.
882+
*
883+
* @return Whether the device is encrypted.
884+
*/
885+
public static boolean isDeviceEncrypted() {
886+
IMountService mountService = IMountService.Stub.asInterface(
887+
ServiceManager.getService("mount"));
888+
try {
889+
return mountService.getEncryptionState() != IMountService.ENCRYPTION_STATE_NONE
890+
&& mountService.getPasswordType() != StorageManager.CRYPT_TYPE_DEFAULT;
891+
} catch (RemoteException re) {
892+
Log.e(TAG, "Error getting encryption state", re);
893+
}
894+
return true;
895+
}
896+
897+
/**
898+
* Clears the encryption password.
899+
*/
900+
public void clearEncryptionPassword() {
901+
updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null);
902+
}
903+
880904
/**
881905
* Retrieves the quality mode we're in.
882906
* {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}

services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import android.util.Pools.SimplePool;
6868
import android.util.Slog;
6969
import android.util.SparseArray;
70+
import android.view.AccessibilityManagerInternal;
7071
import android.view.Display;
7172
import android.view.IWindow;
7273
import android.view.InputDevice;
@@ -91,6 +92,7 @@
9192
import com.android.internal.R;
9293
import com.android.internal.content.PackageMonitor;
9394
import com.android.internal.statusbar.IStatusBarService;
95+
import com.android.internal.widget.LockPatternUtils;
9496
import com.android.server.LocalServices;
9597

9698
import org.xmlpull.v1.XmlPullParserException;
@@ -202,6 +204,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
202204

203205
private final UserManager mUserManager;
204206

207+
private final LockPatternUtils mLockPatternUtils;
208+
205209
private int mCurrentUserId = UserHandle.USER_OWNER;
206210

207211
//TODO: Remove this hack
@@ -225,9 +229,11 @@ public AccessibilityManagerService(Context context) {
225229
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
226230
mSecurityPolicy = new SecurityPolicy();
227231
mMainHandler = new MainHandler(mContext.getMainLooper());
232+
mLockPatternUtils = new LockPatternUtils(context);
228233
registerBroadcastReceivers();
229234
new AccessibilityContentObserver(mMainHandler).register(
230235
context.getContentResolver());
236+
LocalServices.addService(AccessibilityManagerInternal.class, new LocalService());
231237
}
232238

233239
private UserState getUserStateLocked(int userId) {
@@ -1294,6 +1300,7 @@ private void onUserStateChangedLocked(UserState userState) {
12941300
updateTouchExplorationLocked(userState);
12951301
updateEnhancedWebAccessibilityLocked(userState);
12961302
updateDisplayColorAdjustmentSettingsLocked(userState);
1303+
updateEncryptionState(userState);
12971304
scheduleUpdateInputFilter(userState);
12981305
scheduleUpdateClientsIfNeededLocked(userState);
12991306
}
@@ -1570,6 +1577,21 @@ private void updateDisplayColorAdjustmentSettingsLocked(UserState userState) {
15701577
DisplayAdjustmentUtils.applyAdjustments(mContext, userState.mUserId);
15711578
}
15721579

1580+
private void updateEncryptionState(UserState userState) {
1581+
if (userState.mUserId != UserHandle.USER_OWNER) {
1582+
return;
1583+
}
1584+
if (hasRunningServicesLocked(userState) && LockPatternUtils.isDeviceEncrypted()) {
1585+
// If there are running accessibility services we do not have encryption as
1586+
// the user needs the accessibility layer to be running to authenticate.
1587+
mLockPatternUtils.clearEncryptionPassword();
1588+
}
1589+
}
1590+
1591+
private boolean hasRunningServicesLocked(UserState userState) {
1592+
return !userState.mBoundServices.isEmpty() || !userState.mBindingServices.isEmpty();
1593+
}
1594+
15731595
private MagnificationSpec getCompatibleMagnificationSpecLocked(int windowId) {
15741596
IBinder windowToken = mGlobalWindowTokens.get(windowId);
15751597
if (windowToken == null) {
@@ -3883,4 +3905,14 @@ public void onChange(boolean selfChange, Uri uri) {
38833905
}
38843906
}
38853907
}
3908+
3909+
private final class LocalService extends AccessibilityManagerInternal {
3910+
@Override
3911+
public boolean isNonDefaultEncryptionPasswordAllowed() {
3912+
synchronized (mLock) {
3913+
UserState userState = getCurrentUserStateLocked();
3914+
return !hasRunningServicesLocked(userState);
3915+
}
3916+
}
3917+
}
38863918
}

services/core/java/com/android/server/MountService.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import android.util.Slog;
6464
import android.util.Xml;
6565

66+
import android.view.AccessibilityManagerInternal;
6667
import com.android.internal.annotations.GuardedBy;
6768
import com.android.internal.annotations.VisibleForTesting;
6869
import com.android.internal.app.IMediaContainerService;
@@ -557,6 +558,8 @@ public void handleMessage(Message msg) {
557558

558559
private final Handler mHandler;
559560

561+
private final AccessibilityManagerInternal mAccessibilityManagerInternal;
562+
560563
void waitForAsecScan() {
561564
waitForLatch(mAsecsScanned);
562565
}
@@ -1454,6 +1457,9 @@ public MountService(Context context) {
14541457
hthread.start();
14551458
mHandler = new MountServiceHandler(hthread.getLooper());
14561459

1460+
mAccessibilityManagerInternal = LocalServices.getService(
1461+
AccessibilityManagerInternal.class);
1462+
14571463
// Watch for user changes
14581464
final IntentFilter userFilter = new IntentFilter();
14591465
userFilter.addAction(Intent.ACTION_USER_ADDED);
@@ -2254,8 +2260,15 @@ public int changeEncryptionPassword(int type, String password) {
22542260

22552261
final NativeDaemonEvent event;
22562262
try {
2263+
// The accessibility layer may veto having a non-default encryption
2264+
// password because if there are enabled accessibility services the
2265+
// user cannot authenticate as the latter need access to the data.
2266+
if (!TextUtils.isEmpty(password)
2267+
&& !mAccessibilityManagerInternal.isNonDefaultEncryptionPasswordAllowed()) {
2268+
return getEncryptionState();
2269+
}
22572270
event = mConnector.execute("cryptfs", "changepw", CRYPTO_TYPES[type],
2258-
new SensitiveArg(toHex(password)));
2271+
new SensitiveArg(toHex(password)));
22592272
return Integer.parseInt(event.getMessage());
22602273
} catch (NativeDaemonConnectorException e) {
22612274
// Encryption failed
@@ -2302,7 +2315,7 @@ public int verifyEncryptionPassword(String password) throws RemoteException {
23022315
* @return The type, one of the CRYPT_TYPE_XXX consts from StorageManager.
23032316
*/
23042317
@Override
2305-
public int getPasswordType() throws RemoteException {
2318+
public int getPasswordType() {
23062319

23072320
waitForReady();
23082321

0 commit comments

Comments
 (0)