Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7a12849 authored by Chun Zhang's avatar Chun Zhang
Browse files

Add WearSafetySource (Without Listener)

Bug: 389841524
Test: TreeHugger
Test: manual
Test: atest SafetySourceBroadcastReceiverTest
Test: atest LockScreenSafetySourceTest
Test: atest ActiveUnlockStatusUtilsTest
Test: atest WearSafetySourceTest
Flag: com.android.settings.flags.biometrics_onboarding_education
Change-Id: I7f4b41bf33d1e0fb7988f756a466e4d80bcec25e
parent f1d0ce61
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1054,6 +1054,7 @@
    <!-- Watch unlock enrollment and settings --><skip />
    <!-- Title shown for menu item that launches watch unlock settings. [CHAR LIMIT=40] -->
    <string name ="security_settings_activeunlock_preference_title">Watch Unlock</string>
    <string name="security_settings_activeunlock">Watch</string>
    <!-- Introduction shown in face and fingerprint page to introduce the biometric feature. [CHAR LIMIT=NONE]-->
    <string name="biometric_settings_intro_with_activeunlock">When you set up Face Unlock and Fingerprint Unlock, your phone will ask for your fingerprint when you wear a mask or are in a dark area.\n\nWatch Unlock is another convenient way to unlock your phone, for example, when your fingers are wet or face isn\u2019t recognized.</string>
    <!-- Introduction shown in fingerprint page to explain that watch unlock can be used if fingerprint isn't recognized. [CHAR LIMIT=NONE]-->
+39 −18
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.settingslib.utils.ThreadUtils;
@@ -76,17 +77,22 @@ public class ActiveUnlockContentListener {
        mContentKey = contentKey;
        String authority = new ActiveUnlockStatusUtils(mContext).getAuthority();
        if (authority != null) {
            mUri = new Uri.Builder()
                    .scheme(ContentResolver.SCHEME_CONTENT)
                    .authority(authority)
                    .appendPath(CONTENT_PROVIDER_PATH)
                    .build();
            mUri = getUri(authority);
        } else {
            mUri = null;
        }

    }

    /** Returns Active Unlock Uri. */
    public static @NonNull Uri getUri(@NonNull String authority) {
        return new Uri.Builder()
                    .scheme(ContentResolver.SCHEME_CONTENT)
                    .authority(authority)
                    .appendPath(CONTENT_PROVIDER_PATH)
                    .build();
    }

    /** Returns true if start listening for updates from the ContentProvider, false otherwise. */
    public synchronized boolean subscribe() {
        if (mSubscribed || mUri == null) {
@@ -123,25 +129,40 @@ public class ActiveUnlockContentListener {
            Log.e(mLogTag, "Uri null when trying to fetch content");
            return;
        }
        ContentResolver contentResolver = mContext.getContentResolver();
        ContentProviderClient client = contentResolver.acquireContentProviderClient(mUri);
        Bundle bundle;

        @Nullable String newValue = getContentFromUri(
            mContext, mUri, mLogTag, mMethodName, mContentKey);
        if (!TextUtils.equals(mContent, newValue)) {
            mContent = newValue;
            mContentChangedListener.onContentChanged(mContent);
        }
    }

    /** Get the content from Uri. */
    public static @Nullable String getContentFromUri(
            @NonNull Context context,
            @NonNull Uri uri,
            @NonNull String logTag,
            @NonNull String methodName,
            @NonNull String contentKey) {
        ContentResolver contentResolver = context.getContentResolver();
        ContentProviderClient client = contentResolver.acquireContentProviderClient(uri);

        @Nullable Bundle bundle = null;

        try {
            bundle = client.call(mMethodName, null /* arg */, null /* extras */);
            bundle = client.call(methodName, /* arg= */ null, /* extras = */ null);
        } catch (RemoteException e) {
            Log.e(mLogTag, "Failed to call contentProvider", e);
            return;
            Log.e(logTag, "Failed to call contentProvider", e);
        } finally {
            client.close();
        }

        if (bundle == null) {
            Log.e(mLogTag, "Null bundle returned from contentProvider");
            return;
        }
        String newValue = bundle.getString(mContentKey);
        if (!TextUtils.equals(mContent, newValue)) {
            mContent = newValue;
            mContentChangedListener.onContentChanged(mContent);
            Log.e(logTag, "Null bundle returned from contentProvider");
            return null;
        }

        return bundle.getString(contentKey);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import android.content.Context;
/** Listens to device name updates from the content provider and fetches the latest value. */
public class ActiveUnlockDeviceNameListener  {
    private static final String TAG = "ActiveUnlockDeviceNameListener";
    private static final String METHOD_NAME = "getDeviceName";
    private static final String DEVICE_NAME_KEY = "com.android.settings.active_unlock.device_name";
    static final String METHOD_NAME = "getDeviceName";
    static final String DEVICE_NAME_KEY = "com.android.settings.active_unlock.device_name";

    private final ActiveUnlockContentListener mActiveUnlockContentListener;
    public ActiveUnlockDeviceNameListener(
+32 −1
Original line number Diff line number Diff line
@@ -155,10 +155,17 @@ public class ActiveUnlockStatusUtils {
        return BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
    }

    /**
     * Returns the title of active unlock only.
     */
    public @NonNull String getTitleForActiveUnlockOnly() {
        return mContext.getString(R.string.security_settings_activeunlock);
    }

    /**
     * Returns the title of the combined biometric settings entity when active unlock is enabled.
     */
    public String getTitleForActiveUnlock() {
    public @NonNull String getTitleForActiveUnlock() {
        final boolean faceAllowed = Utils.hasFaceHardware(mContext);
        final boolean fingerprintAllowed = Utils.hasFingerprintHardware(mContext);
        return mContext.getString(getTitleRes(faceAllowed, fingerprintAllowed));
@@ -264,6 +271,30 @@ public class ActiveUnlockStatusUtils {
        return mContext.getString(getUseBiometricTitleRes(faceAllowed, fingerprintAllowed));
    }

    /**
     * Returns the summary from content provider.
     */
    @Nullable
    public static String getSummaryFromContentProvider(
            @NonNull Context context, @NonNull String authority, @NonNull String logTag) {
        return ActiveUnlockContentListener.getContentFromUri(
            context, ActiveUnlockContentListener.getUri(authority), logTag,
            ActiveUnlockSummaryListener.METHOD_NAME,
            ActiveUnlockSummaryListener.SUMMARY_KEY);
    }

    /**
     * Returns the device name from content provider.
     */
    @Nullable
    public static String getDeviceNameFromContentProvider(
            @NonNull Context context, @NonNull String authority, @NonNull String logTag) {
        return ActiveUnlockContentListener.getContentFromUri(
            context, ActiveUnlockContentListener.getUri(authority), logTag,
            ActiveUnlockDeviceNameListener.METHOD_NAME,
            ActiveUnlockDeviceNameListener.DEVICE_NAME_KEY);
    }

    @StringRes
    private static int getUseBiometricTitleRes(
            boolean isFaceAllowed, boolean isFingerprintAllowed) {
+2 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import android.content.Context;
/** Listens to summary updates from the content provider and fetches the latest value. */
public class ActiveUnlockSummaryListener {
    private static final String TAG = "ActiveUnlockSummaryListener";
    private static final String METHOD_NAME = "getSummary";
    private static final String SUMMARY_KEY = "com.android.settings.summary";
    static final String METHOD_NAME = "getSummary";
    static final String SUMMARY_KEY = "com.android.settings.summary";

    private final ActiveUnlockContentListener mContentListener;
    public ActiveUnlockSummaryListener(
Loading