Skip to content

Commit

Permalink
feat : implementation pause apps
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSluffy committed Jan 1, 2025
1 parent 8b35a95 commit 1e9b737
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lawnchair/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="com.google.android.apps.nexuslauncher.permission.QSB" />
<uses-permission android:name="com.kieronquinn.app.smartspacer.permission.ACCESS_SMARTSPACER"/>
Expand All @@ -29,11 +29,12 @@
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.WRITE_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
<uses-permission android:name="android.permission.MANAGE_USERS"/>
<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES" />
<uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.MANAGE_USERS" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.STATUS_BAR_SERVICE" tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.SUSPEND_APPS" tools:ignore="ProtectedPermissions" />

<!--override minSdk declared in it-->
<uses-sdk tools:overrideLibrary="com.kieronquinn.app.smartspacer.sdk" />
Expand Down
7 changes: 7 additions & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,13 @@
<string name="hotseat_bg_vertical_inset_bottom">Vertical inset (Bottom)</string>


<!-- Pause apps shortcut -->
<string name="pause">Pause</string>
<string name="pause_apps_dialog_title">Pause %1$s?</string>
<string name="pause_apps_dialog_message">Notifications for %1$s will be paused</string>
<string name="paused_apps_dialog_title">App paused</string>
<string name="paused_apps_dialog_message">%1$s was directly paused from the launcher</string>
<string name="paused_apps_drop_target_label">Pause app</string>

<string name="dock_icons">Dock icons</string>
<string name="hotseat_bottom_space_label">Bottom padding</string>
Expand Down
8 changes: 7 additions & 1 deletion lawnchair/src/app/lawnchair/LawnchairLauncher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ class LawnchairLauncher : QuickstepLauncher() {
}

override fun getSupportedShortcuts(): Stream<SystemShortcut.Factory<*>> =
Stream.concat(super.getSupportedShortcuts(), Stream.of(LawnchairShortcut.UNINSTALL, LawnchairShortcut.CUSTOMIZE))
Stream.concat(
super.getSupportedShortcuts(),
Stream.concat(
Stream.of(LawnchairShortcut.UNINSTALL, LawnchairShortcut.CUSTOMIZE),
if (LawnchairApp.isRecentsEnabled) Stream.of(LawnchairShortcut.PAUSE_APPS) else Stream.empty(),
),
)

override fun updateTheme() {
if (themeProvider.colorScheme != colorScheme) {
Expand Down
67 changes: 67 additions & 0 deletions lawnchair/src/app/lawnchair/ui/popup/LawnchairShortcut.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package app.lawnchair.ui.popup

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.AppGlobals
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps
import android.content.pm.SuspendDialogInfo
import android.net.Uri
import android.os.UserHandle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.compose.foundation.layout.PaddingValues
Expand Down Expand Up @@ -65,6 +70,15 @@ class LawnchairShortcut {
}
UnInstall(activity, itemInfo, view)
}

val PAUSE_APPS = SystemShortcut.Factory { activity: LawnchairLauncher, itemInfo: ItemInfo, originalView: View ->
val targetCmp = itemInfo.targetComponent
val packageName = targetCmp?.packageName ?: return@Factory null

if (PackageManagerHelper(activity).isAppSuspended(packageName, itemInfo.user)) return@Factory null

PauseApps(activity, itemInfo, originalView)
}
}

class Customize(
Expand Down Expand Up @@ -97,6 +111,59 @@ class LawnchairShortcut {
}
}

class PauseApps(
target: LawnchairLauncher,
itemInfo: ItemInfo,
originalView: View,
) : SystemShortcut<LawnchairLauncher>(
R.drawable.ic_hourglass_top,
R.string.paused_apps_drop_target_label,
target,
itemInfo,
originalView,
) {
@SuppressLint("NewApi")
override fun onClick(view: View) {
val context = view.context
val appLabel = PackageManagerHelper(context).getApplicationInfo(
mItemInfo.targetComponent?.packageName ?: "",
mItemInfo.user,
0,
)?.let {
context.packageManager.getApplicationLabel(
it,
)
}
AlertDialog.Builder(context)
.setIcon(R.drawable.ic_hourglass_top)
.setTitle(context.getString(R.string.pause_apps_dialog_title, appLabel))
.setMessage(context.getString(R.string.pause_apps_dialog_message, appLabel))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.pause) { _, _ ->
try {
AppGlobals.getPackageManager().setPackagesSuspendedAsUser(
arrayOf(mItemInfo.targetComponent?.packageName ?: ""),
true, null, null,
SuspendDialogInfo.Builder()
.setIcon(R.drawable.ic_hourglass_top)
.setTitle(R.string.paused_apps_dialog_title)
.setMessage(R.string.paused_apps_dialog_message)
.setNeutralButtonAction(SuspendDialogInfo.BUTTON_ACTION_UNSUSPEND)
.build(),
0,
context.opPackageName,
context.userId,
mItemInfo.user.identifier,
)
} catch (e: Throwable) {
Log.e("LawnchairShortcut", "Failed to pause app", e)
}
}
.show()
AbstractFloatingView.closeAllOpenViews(mTarget)
}
}

class UnInstall(private var target: BaseDraggingActivity?, private var itemInfo: ItemInfo?, originalView: View?) :
SystemShortcut<BaseDraggingActivity>(
R.drawable.ic_uninstall_no_shadow,
Expand Down

0 comments on commit 1e9b737

Please sign in to comment.