Search in sources :

Example 6 with InternalStateHandler

use of com.android.launcher3.states.InternalStateHandler in project android_packages_apps_Launcher3 by ArrowOS.

the class Launcher method onCreate.

@Override
@TargetApi(Build.VERSION_CODES.S)
protected void onCreate(Bundle savedInstanceState) {
    // Only use a hard-coded cookie since we only want to trace this once.
    if (Utilities.ATLEAST_S) {
        Trace.beginAsyncSection(DISPLAY_WORKSPACE_TRACE_METHOD_NAME, DISPLAY_WORKSPACE_TRACE_COOKIE);
        Trace.beginAsyncSection(DISPLAY_ALL_APPS_TRACE_METHOD_NAME, DISPLAY_ALL_APPS_TRACE_COOKIE);
    }
    Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, TraceHelper.FLAG_UI_EVENT);
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }
    if (Utilities.IS_DEBUG_DEVICE && FeatureFlags.NOTIFY_CRASHES.get()) {
        final String notificationChannelId = "com.android.launcher3.Debug";
        final String notificationChannelName = "Debug";
        final String notificationTag = "Debug";
        final int notificationId = 0;
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(new NotificationChannel(notificationChannelId, notificationChannelName, NotificationManager.IMPORTANCE_HIGH));
        Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
            String stackTrace = Log.getStackTraceString(throwable);
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_TEXT, stackTrace);
            shareIntent = Intent.createChooser(shareIntent, null);
            PendingIntent sharePendingIntent = PendingIntent.getActivity(this, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            Notification notification = new Notification.Builder(this, notificationChannelId).setSmallIcon(android.R.drawable.ic_menu_close_clear_cancel).setContentTitle("Launcher crash detected!").setStyle(new Notification.BigTextStyle().bigText(stackTrace)).addAction(android.R.drawable.ic_menu_share, "Share", sharePendingIntent).build();
            notificationManager.notify(notificationTag, notificationId, notification);
            Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
            if (defaultUncaughtExceptionHandler != null) {
                defaultUncaughtExceptionHandler.uncaughtException(thread, throwable);
            }
        });
    }
    super.onCreate(savedInstanceState);
    LauncherAppState app = LauncherAppState.getInstance(this);
    mOldConfig = new Configuration(getResources().getConfiguration());
    mModel = app.getModel();
    mRotationHelper = new RotationHelper(this);
    InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
    initDeviceProfile(idp);
    idp.addOnChangeListener(this);
    mSharedPrefs = Utilities.getPrefs(this);
    mIconCache = app.getIconCache();
    mAccessibilityDelegate = createAccessibilityDelegate();
    mDragController = new LauncherDragController(this);
    mAllAppsController = new AllAppsTransitionController(this);
    mStateManager = new StateManager<>(this, NORMAL);
    mOnboardingPrefs = createOnboardingPrefs(mSharedPrefs);
    mAppWidgetManager = new WidgetManagerHelper(this);
    mAppWidgetHost = createAppWidgetHost();
    mAppWidgetHost.startListening();
    inflateRootView(R.layout.launcher);
    setupViews();
    crossFadeWithPreviousAppearance();
    mPopupDataProvider = new PopupDataProvider(this::updateNotificationDots);
    boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this);
    if (internalStateHandled) {
        if (savedInstanceState != null) {
            // InternalStateHandler has already set the appropriate state.
            // We dont need to do anything.
            savedInstanceState.remove(RUNTIME_STATE);
        }
    }
    restoreState(savedInstanceState);
    mStateManager.reapplyState();
    if (savedInstanceState != null) {
        int[] pageIds = savedInstanceState.getIntArray(RUNTIME_STATE_CURRENT_SCREEN_IDS);
        if (pageIds != null) {
            mPagesToBindSynchronously = IntSet.wrap(pageIds);
        }
    }
    if (!mModel.addCallbacksAndLoad(this)) {
        if (!internalStateHandled) {
            // If we are not binding synchronously, show a fade in animation when
            // the first page bind completes.
            mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
        }
    }
    // For handling default keys
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    setContentView(getRootView());
    getRootView().dispatchInsets();
    // Listen for broadcasts
    registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }
    mOverlayManager = getDefaultOverlay();
    PluginManagerWrapper.INSTANCE.get(this).addPluginListener(this, OverlayPlugin.class, false);
    mRotationHelper.initialize();
    TraceHelper.INSTANCE.endSection(traceToken);
    mUserChangedCallbackCloseable = UserCache.INSTANCE.get(this).addUserChangeListener(() -> getStateManager().goToState(NORMAL));
    if (Utilities.ATLEAST_R) {
        getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
    }
}
Also used : Configuration(android.content.res.Configuration) PropertyListBuilder(com.android.launcher3.anim.PropertyListBuilder) Notification(android.app.Notification) StrictMode(android.os.StrictMode) AllAppsTransitionController(com.android.launcher3.allapps.AllAppsTransitionController) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) RotationHelper(com.android.launcher3.states.RotationHelper) PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) NotificationChannel(android.app.NotificationChannel) DragObject(com.android.launcher3.DropTarget.DragObject) LauncherDragController(com.android.launcher3.dragndrop.LauncherDragController) PendingIntent(android.app.PendingIntent) TargetApi(android.annotation.TargetApi)

Example 7 with InternalStateHandler

use of com.android.launcher3.states.InternalStateHandler in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Launcher method onCreate.

@Override
@TargetApi(Build.VERSION_CODES.S)
protected void onCreate(Bundle savedInstanceState) {
    // Only use a hard-coded cookie since we only want to trace this once.
    if (Utilities.ATLEAST_S) {
        Trace.beginAsyncSection(DISPLAY_WORKSPACE_TRACE_METHOD_NAME, DISPLAY_WORKSPACE_TRACE_COOKIE);
        Trace.beginAsyncSection(DISPLAY_ALL_APPS_TRACE_METHOD_NAME, DISPLAY_ALL_APPS_TRACE_COOKIE);
    }
    Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, TraceHelper.FLAG_UI_EVENT);
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }
    if (Utilities.IS_DEBUG_DEVICE && FeatureFlags.NOTIFY_CRASHES.get()) {
        final String notificationChannelId = "com.android.launcher3.Debug";
        final String notificationChannelName = "Debug";
        final String notificationTag = "Debug";
        final int notificationId = 0;
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(new NotificationChannel(notificationChannelId, notificationChannelName, NotificationManager.IMPORTANCE_HIGH));
        Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
            String stackTrace = Log.getStackTraceString(throwable);
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_TEXT, stackTrace);
            shareIntent = Intent.createChooser(shareIntent, null);
            PendingIntent sharePendingIntent = PendingIntent.getActivity(this, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            Notification notification = new Notification.Builder(this, notificationChannelId).setSmallIcon(android.R.drawable.ic_menu_close_clear_cancel).setContentTitle("Launcher crash detected!").setStyle(new Notification.BigTextStyle().bigText(stackTrace)).addAction(android.R.drawable.ic_menu_share, "Share", sharePendingIntent).build();
            notificationManager.notify(notificationTag, notificationId, notification);
            Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
            if (defaultUncaughtExceptionHandler != null) {
                defaultUncaughtExceptionHandler.uncaughtException(thread, throwable);
            }
        });
    }
    super.onCreate(savedInstanceState);
    LauncherAppState app = LauncherAppState.getInstance(this);
    mOldConfig = new Configuration(getResources().getConfiguration());
    mModel = app.getModel();
    mRotationHelper = new RotationHelper(this);
    InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
    initDeviceProfile(idp);
    idp.addOnChangeListener(this);
    mSharedPrefs = Utilities.getPrefs(this);
    mIconCache = app.getIconCache();
    mAccessibilityDelegate = createAccessibilityDelegate();
    mDragController = new LauncherDragController(this);
    mAllAppsController = new AllAppsTransitionController(this);
    mStateManager = new StateManager<>(this, NORMAL);
    mOnboardingPrefs = createOnboardingPrefs(mSharedPrefs);
    mAppWidgetManager = new WidgetManagerHelper(this);
    mAppWidgetHost = createAppWidgetHost();
    mAppWidgetHost.startListening();
    inflateRootView(R.layout.launcher);
    setupViews();
    crossFadeWithPreviousAppearance();
    mPopupDataProvider = new PopupDataProvider(this::updateNotificationDots);
    boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this);
    if (internalStateHandled) {
        if (savedInstanceState != null) {
            // InternalStateHandler has already set the appropriate state.
            // We dont need to do anything.
            savedInstanceState.remove(RUNTIME_STATE);
        }
    }
    restoreState(savedInstanceState);
    mStateManager.reapplyState();
    if (savedInstanceState != null) {
        int[] pageIds = savedInstanceState.getIntArray(RUNTIME_STATE_CURRENT_SCREEN_IDS);
        if (pageIds != null) {
            mPagesToBindSynchronously = IntSet.wrap(pageIds);
        }
    }
    if (!mModel.addCallbacksAndLoad(this)) {
        if (!internalStateHandled) {
            // If we are not binding synchronously, show a fade in animation when
            // the first page bind completes.
            mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD).setValue(0);
        }
    }
    // For handling default keys
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    setContentView(getRootView());
    getRootView().dispatchInsets();
    // Listen for broadcasts
    registerReceiver(mScreenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));
    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }
    mOverlayManager = getDefaultOverlay();
    PluginManagerWrapper.INSTANCE.get(this).addPluginListener(this, OverlayPlugin.class, false);
    mRotationHelper.initialize();
    TraceHelper.INSTANCE.endSection(traceToken);
    mUserChangedCallbackCloseable = UserCache.INSTANCE.get(this).addUserChangeListener(() -> getStateManager().goToState(NORMAL));
    if (Utilities.ATLEAST_R) {
        getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
    }
}
Also used : Configuration(android.content.res.Configuration) PropertyListBuilder(com.android.launcher3.anim.PropertyListBuilder) Notification(android.app.Notification) StrictMode(android.os.StrictMode) AllAppsTransitionController(com.android.launcher3.allapps.AllAppsTransitionController) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) RotationHelper(com.android.launcher3.states.RotationHelper) PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) NotificationChannel(android.app.NotificationChannel) DragObject(com.android.launcher3.DropTarget.DragObject) LauncherDragController(com.android.launcher3.dragndrop.LauncherDragController) PendingIntent(android.app.PendingIntent) TargetApi(android.annotation.TargetApi)

Aggregations

Intent (android.content.Intent)7 IntentFilter (android.content.IntentFilter)7 Configuration (android.content.res.Configuration)7 StrictMode (android.os.StrictMode)7 DragObject (com.android.launcher3.DropTarget.DragObject)7 AllAppsTransitionController (com.android.launcher3.allapps.AllAppsTransitionController)7 PropertyListBuilder (com.android.launcher3.anim.PropertyListBuilder)7 PopupDataProvider (com.android.launcher3.popup.PopupDataProvider)7 RotationHelper (com.android.launcher3.states.RotationHelper)7 TargetApi (android.annotation.TargetApi)6 Notification (android.app.Notification)5 NotificationChannel (android.app.NotificationChannel)5 NotificationManager (android.app.NotificationManager)5 PendingIntent (android.app.PendingIntent)5 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)5 LauncherDragController (com.android.launcher3.dragndrop.LauncherDragController)4 Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2