Gracefully handle slowly appearing Home apps.
When starting a Guest user for the first time, it can take quite awhile before the Home app enables itself. So if we're unlocked and no other Home app is around, chill for 500ms and see if someone showed up. Bug: 26267450 Change-Id: I3c4e01ae3681c650ea90b20ffc21835ae264b5e9
This commit is contained in:
@@ -21,25 +21,57 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class FallbackHome extends Activity {
|
||||
private static final String TAG = "FallbackHome";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
|
||||
maybeFinish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "User unlocked; leaving to find real home");
|
||||
unregisterReceiver(this);
|
||||
finish();
|
||||
maybeFinish();
|
||||
}
|
||||
};
|
||||
|
||||
private void maybeFinish() {
|
||||
if (getSystemService(UserManager.class).isUserUnlocked()) {
|
||||
final Intent homeIntent = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_HOME);
|
||||
final ResolveInfo homeInfo = getPackageManager().resolveActivity(homeIntent, 0);
|
||||
if (Objects.equals(getPackageName(), homeInfo.activityInfo.packageName)) {
|
||||
Log.d(TAG, "User unlocked but no home; let's hope someone enables one soon?");
|
||||
mHandler.sendEmptyMessageDelayed(0, 500);
|
||||
} else {
|
||||
Log.d(TAG, "User unlocked and real home found; let's go!");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
maybeFinish();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user