Merge "Add tron logging for retail demo session counters" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
30a2b43f6d
@@ -922,6 +922,8 @@ public final class Pm {
|
|||||||
flags |= UserInfo.FLAG_EPHEMERAL;
|
flags |= UserInfo.FLAG_EPHEMERAL;
|
||||||
} else if ("--guest".equals(opt)) {
|
} else if ("--guest".equals(opt)) {
|
||||||
flags |= UserInfo.FLAG_GUEST;
|
flags |= UserInfo.FLAG_GUEST;
|
||||||
|
} else if ("--demo".equals(opt)) {
|
||||||
|
flags |= UserInfo.FLAG_DEMO;
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Error: unknown option " + opt);
|
System.err.println("Error: unknown option " + opt);
|
||||||
return showUsage();
|
return showUsage();
|
||||||
|
|||||||
@@ -153,7 +153,8 @@ public class KeyguardStatusBarView extends RelativeLayout
|
|||||||
if (mKeyguardUserSwitcher == null) {
|
if (mKeyguardUserSwitcher == null) {
|
||||||
// If we have no keyguard switcher, the screen width is under 600dp. In this case,
|
// If we have no keyguard switcher, the screen width is under 600dp. In this case,
|
||||||
// we don't show the multi-user avatar unless there is more than 1 user on the device.
|
// we don't show the multi-user avatar unless there is more than 1 user on the device.
|
||||||
if (mUserSwitcherController.getSwitchableUserCount() > 1) {
|
if (mUserSwitcherController != null
|
||||||
|
&& mUserSwitcherController.getSwitchableUserCount() > 1) {
|
||||||
mMultiUserSwitch.setVisibility(View.VISIBLE);
|
mMultiUserSwitch.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
mMultiUserSwitch.setVisibility(View.GONE);
|
mMultiUserSwitch.setVisibility(View.GONE);
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ import android.provider.Settings;
|
|||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import com.android.internal.os.BackgroundThread;
|
import com.android.internal.os.BackgroundThread;
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
|
import com.android.internal.annotations.GuardedBy;
|
||||||
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.server.LocalServices;
|
import com.android.server.LocalServices;
|
||||||
import com.android.server.ServiceThread;
|
import com.android.server.ServiceThread;
|
||||||
@@ -86,8 +88,12 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
AudioSystem.STREAM_MUSIC
|
AudioSystem.STREAM_MUSIC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Tron Vars
|
||||||
|
private static final String DEMO_SESSION_COUNT = "retail_demo_session_count";
|
||||||
|
private static final String DEMO_SESSION_DURATION = "retail_demo_session_duration";
|
||||||
|
|
||||||
boolean mDeviceInDemoMode = false;
|
boolean mDeviceInDemoMode = false;
|
||||||
int mCurrentUserId;
|
int mCurrentUserId = UserHandle.USER_SYSTEM;
|
||||||
private ActivityManagerService mAms;
|
private ActivityManagerService mAms;
|
||||||
private ActivityManagerInternal mAmi;
|
private ActivityManagerInternal mAmi;
|
||||||
private AudioManager mAudioManager;
|
private AudioManager mAudioManager;
|
||||||
@@ -102,6 +108,15 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
private String[] mCameraIdsWithFlash;
|
private String[] mCameraIdsWithFlash;
|
||||||
private Configuration mPrimaryUserConfiguration;
|
private Configuration mPrimaryUserConfiguration;
|
||||||
|
|
||||||
|
final Object mActivityLock = new Object();
|
||||||
|
// Whether the newly created demo user has interacted with the screen yet
|
||||||
|
@GuardedBy("mActivityLock")
|
||||||
|
boolean mUserUntouched;
|
||||||
|
@GuardedBy("mActivityLock")
|
||||||
|
long mFirstUserActivityTime;
|
||||||
|
@GuardedBy("mActivityLock")
|
||||||
|
long mLastUserActivityTime;
|
||||||
|
|
||||||
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -136,18 +151,7 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
break;
|
break;
|
||||||
case MSG_INACTIVITY_TIME_OUT:
|
case MSG_INACTIVITY_TIME_OUT:
|
||||||
final IPackageManager pm = AppGlobals.getPackageManager();
|
if (isDemoLauncherDisabled()) {
|
||||||
int enabledState = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
|
|
||||||
String demoLauncherComponent = getContext().getResources()
|
|
||||||
.getString(R.string.config_demoModeLauncherComponent);
|
|
||||||
try {
|
|
||||||
enabledState = pm.getComponentEnabledSetting(
|
|
||||||
ComponentName.unflattenFromString(demoLauncherComponent),
|
|
||||||
mCurrentUserId);
|
|
||||||
} catch (RemoteException exc) {
|
|
||||||
Slog.e(TAG, "Unable to talk to Package Manager", exc);
|
|
||||||
}
|
|
||||||
if (enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
|
|
||||||
Slog.i(TAG, "User inactivity timeout reached");
|
Slog.i(TAG, "User inactivity timeout reached");
|
||||||
showInactivityCountdownDialog();
|
showInactivityCountdownDialog();
|
||||||
}
|
}
|
||||||
@@ -158,6 +162,9 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
}
|
}
|
||||||
removeMessages(MSG_START_NEW_SESSION);
|
removeMessages(MSG_START_NEW_SESSION);
|
||||||
removeMessages(MSG_INACTIVITY_TIME_OUT);
|
removeMessages(MSG_INACTIVITY_TIME_OUT);
|
||||||
|
if (mCurrentUserId != UserHandle.USER_SYSTEM) {
|
||||||
|
logSessionDuration();
|
||||||
|
}
|
||||||
final UserInfo demoUser = getUserManager().createUser(DEMO_USER_NAME,
|
final UserInfo demoUser = getUserManager().createUser(DEMO_USER_NAME,
|
||||||
UserInfo.FLAG_DEMO | UserInfo.FLAG_EPHEMERAL);
|
UserInfo.FLAG_DEMO | UserInfo.FLAG_EPHEMERAL);
|
||||||
if (demoUser != null) {
|
if (demoUser != null) {
|
||||||
@@ -190,6 +197,9 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
|
|
||||||
public RetailDemoModeService(Context context) {
|
public RetailDemoModeService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
synchronized (mActivityLock) {
|
||||||
|
mFirstUserActivityTime = mLastUserActivityTime = SystemClock.uptimeMillis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Notification createResetNotification() {
|
private Notification createResetNotification() {
|
||||||
@@ -213,6 +223,21 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
return mResetDemoPendingIntent;
|
return mResetDemoPendingIntent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isDemoLauncherDisabled() {
|
||||||
|
IPackageManager pm = AppGlobals.getPackageManager();
|
||||||
|
int enabledState = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
|
||||||
|
String demoLauncherComponent = getContext().getResources()
|
||||||
|
.getString(R.string.config_demoModeLauncherComponent);
|
||||||
|
try {
|
||||||
|
enabledState = pm.getComponentEnabledSetting(
|
||||||
|
ComponentName.unflattenFromString(demoLauncherComponent),
|
||||||
|
mCurrentUserId);
|
||||||
|
} catch (RemoteException exc) {
|
||||||
|
Slog.e(TAG, "Unable to talk to Package Manager", exc);
|
||||||
|
}
|
||||||
|
return enabledState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||||
|
}
|
||||||
|
|
||||||
private void setupDemoUser(UserInfo userInfo) {
|
private void setupDemoUser(UserInfo userInfo) {
|
||||||
UserManager um = getUserManager();
|
UserManager um = getUserManager();
|
||||||
UserHandle user = UserHandle.of(userInfo.id);
|
UserHandle user = UserHandle.of(userInfo.id);
|
||||||
@@ -226,6 +251,14 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
Settings.Secure.SKIP_FIRST_USE_HINTS, 1, userInfo.id);
|
Settings.Secure.SKIP_FIRST_USE_HINTS, 1, userInfo.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void logSessionDuration() {
|
||||||
|
final int sessionDuration;
|
||||||
|
synchronized (mActivityLock) {
|
||||||
|
sessionDuration = (int) ((mLastUserActivityTime - mFirstUserActivityTime) / 1000);
|
||||||
|
}
|
||||||
|
MetricsLogger.count(getContext(), DEMO_SESSION_DURATION, sessionDuration);
|
||||||
|
}
|
||||||
|
|
||||||
private ActivityManagerService getActivityManager() {
|
private ActivityManagerService getActivityManager() {
|
||||||
if (mAms == null) {
|
if (mAms == null) {
|
||||||
mAms = (ActivityManagerService) ActivityManagerNative.getDefault();
|
mAms = (ActivityManagerService) ActivityManagerNative.getDefault();
|
||||||
@@ -395,11 +428,15 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
turnOffAllFlashLights();
|
turnOffAllFlashLights();
|
||||||
muteVolumeStreams();
|
muteVolumeStreams();
|
||||||
mAmi.updatePersistentConfigurationForUser(getPrimaryUsersConfiguration(), userId);
|
mAmi.updatePersistentConfigurationForUser(getPrimaryUsersConfiguration(), userId);
|
||||||
|
synchronized (mActivityLock) {
|
||||||
|
mUserUntouched = true;
|
||||||
|
}
|
||||||
|
MetricsLogger.count(getContext(), DEMO_SESSION_COUNT, 1);
|
||||||
|
mHandler.removeMessages(MSG_INACTIVITY_TIME_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RetailDemoModeServiceInternal mLocalService = new RetailDemoModeServiceInternal() {
|
private RetailDemoModeServiceInternal mLocalService = new RetailDemoModeServiceInternal() {
|
||||||
private static final long USER_ACTIVITY_DEBOUNCE_TIME = 2000;
|
private static final long USER_ACTIVITY_DEBOUNCE_TIME = 2000;
|
||||||
private long mLastUserActivityTime = 0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUserActivity() {
|
public void onUserActivity() {
|
||||||
@@ -407,10 +444,17 @@ public class RetailDemoModeService extends SystemService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long timeOfActivity = SystemClock.uptimeMillis();
|
long timeOfActivity = SystemClock.uptimeMillis();
|
||||||
|
synchronized (mActivityLock) {
|
||||||
if (timeOfActivity < mLastUserActivityTime + USER_ACTIVITY_DEBOUNCE_TIME) {
|
if (timeOfActivity < mLastUserActivityTime + USER_ACTIVITY_DEBOUNCE_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mLastUserActivityTime = timeOfActivity;
|
mLastUserActivityTime = timeOfActivity;
|
||||||
|
if (mUserUntouched && isDemoLauncherDisabled()) {
|
||||||
|
Slog.d(TAG, "retail_demo first touch");
|
||||||
|
mUserUntouched = false;
|
||||||
|
mFirstUserActivityTime = timeOfActivity;
|
||||||
|
}
|
||||||
|
}
|
||||||
mHandler.removeMessages(MSG_INACTIVITY_TIME_OUT);
|
mHandler.removeMessages(MSG_INACTIVITY_TIME_OUT);
|
||||||
mHandler.sendEmptyMessageDelayed(MSG_INACTIVITY_TIME_OUT, USER_INACTIVITY_TIMEOUT);
|
mHandler.sendEmptyMessageDelayed(MSG_INACTIVITY_TIME_OUT, USER_INACTIVITY_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user