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

Commit 8d1c3d60 authored by Andy Mast's avatar Andy Mast
Browse files

Keyguard Fingerprint: Send Unlock Stats

Change-Id: I2feac5db2604cef85ea9eafd69e1bc2272ff2d93

Conflicts:
	packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
parent e8cd6175
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
    <uses-permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE" />
    <uses-permission android:name="android.permission.TRUST_LISTENER" />
    <uses-permission android:name="android.permission.ACCESS_FINGERPRINT_SERVICE" />
    <uses-permission android:name="com.cyngn.stats.SEND_ANALYTICS" />

    <application android:label="@string/app_name"
        android:process="com.android.systemui"
+15 −1
Original line number Diff line number Diff line
@@ -1545,11 +1545,21 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
        return mFailedAttempts;
    }

    public int getFailedFingerprintUnlockAttempts() {
        return mFailedFingerprintAttempts;
    }

    public void clearFailedUnlockAttempts() {
        clearFailedUnlockAttempts(false);
    }

    public void clearFailedUnlockAttempts(boolean clearFingers) {
        mFailedAttempts = 0;
        mFailedBiometricUnlockAttempts = 0;
        if (clearFingers) {
            mFailedFingerprintAttempts = 0;
        }
    }

    public void startFingerAuthIfUsingFingerprint() {
        if (mLockPatternUtils.usingFingerprint()) {
@@ -1573,6 +1583,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
        mUserFingerprintRecognized.clear();
    }

    public boolean isFingerprintRecognized() {
       return (mUserFingerprintRecognized.size() > 0);
    }

    public void reportFailedUnlockAttempt() {
        mFailedAttempts++;
    }
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.keyguard.cmstats;

import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.util.Log;

public class KeyguardStats {
    private static final String TAG = KeyguardStats.class.getSimpleName();
    private static final String ANALYTIC_INTENT = "com.cyngn.stats.action.SEND_ANALYTIC_EVENT";
    private static final String ANALYTIC_PERMISSION = "com.cyngn.stats.SEND_ANALYTICS";
    public static final String TRACKING_ID = "tracking_id";
    private static final boolean DEBUG = false;

    private KeyguardStats() {}

    public static void sendUnlockEvent(Context context,
            boolean fingerprintUsed,
            int numAttempts) {
        Intent intent = new Intent();
        intent.putExtra(Fields.EVENT_ACTION, Action.UNLOCKED);
        intent.putExtra(Fields.EVENT_CATEGORY, Categories.KEYGUARD);
        intent.putExtra(Fields.FINGERPRINT_USED_TO_UNLOCK, fingerprintUsed);
        intent.putExtra(Fields.NUM_FINGERPRINT_UNLOCK_ATTEMPTS, numAttempts);
        sendEvent(context, intent);
    }

    private static void sendEvent(Context context, Intent intent) {
        if (!StatsUtils.isStatsPackageInstalled(context)
                || !StatsUtils.isStatsCollectionEnabled(context)) {
            return;
        }

        intent.setAction(ANALYTIC_INTENT);
        intent.putExtra(TRACKING_ID, context.getPackageName());

        if (DEBUG) {
            Log.d(TAG, "Sending " + intent.toInsecureString());
        }

        // broadcast for internal package
        context.sendBroadcastAsUser(intent,
                new UserHandle(UserHandle.USER_CURRENT), ANALYTIC_PERMISSION);
    }

    public static final class Fields {
        public static final String EVENT_CATEGORY = "category";
        public static final String EVENT_ACTION = "action";
        public static final String NUM_FINGERPRINT_UNLOCK_ATTEMPTS = "numFingerprintUnlockAttempts";
        public static final String FINGERPRINT_USED_TO_UNLOCK = "fingerprintUsedToUnlock";
    }

    public static final class Categories {
        public static final String KEYGUARD = "keyguard";
    }

    public static final class Action {
        public static final String UNLOCKED = "unlocked";
    }
}
+43 −0
Original line number Diff line number Diff line

/*
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.keyguard.cmstats;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.provider.Settings;

public class StatsUtils {
    private static final String STATS_PACKAGE = "com.cyngn.stats";

    public static boolean isStatsCollectionEnabled(Context context) {
        return Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.STATS_COLLECTION, 1) != 0;
    }

    public static boolean isStatsPackageInstalled(Context context) {
        try {
            PackageInfo pi = context.getPackageManager().getPackageInfo(STATS_PACKAGE, 0);
            return pi.applicationInfo.enabled
                    && ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@

    <!-- Fingerprint -->
    <uses-permission android:name="android.permission.ACCESS_FINGERPRINT_SERVICE" />
    <uses-permission android:name="com.cyngn.stats.SEND_ANALYTICS" />

    <application
        android:name=".SystemUIApplication"
Loading