forked from microg/GmsCore
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable work app store only after adding a work account
- Loading branch information
Showing
5 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
vending-app/src/main/java/org/microg/vending/WorkAccountChangedReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.microg.vending | ||
|
||
import android.accounts.AccountManager | ||
import android.content.BroadcastReceiver | ||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.util.Log | ||
import org.microg.vending.ui.VendingActivity | ||
|
||
class WorkAccountChangedReceiver : BroadcastReceiver() { | ||
|
||
override fun onReceive(context: Context, intent: Intent?) { | ||
val accountManager = AccountManager.get(context) | ||
val hasWorkAccounts = accountManager.getAccountsByType("com.google.work").isNotEmpty() | ||
|
||
Log.d(TAG, "setting VendingActivity state to enabled = $hasWorkAccounts") | ||
|
||
val componentName = ComponentName( | ||
context, | ||
VendingActivity::class.java | ||
Check failure on line 22 in vending-app/src/main/java/org/microg/vending/WorkAccountChangedReceiver.kt GitHub Actions / Gradle build
|
||
) | ||
context.packageManager.setComponentEnabledSetting( | ||
componentName, | ||
if (hasWorkAccounts) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, | ||
0 | ||
) | ||
} | ||
|
||
companion object { | ||
const val TAG = "GmsVendingWorkAccRcvr" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters