### Installing APK Across Profiles Source: https://context7.com/petercxy/shelter/llms.txt Shows how to install APK files from one Android profile into another using cross-profile content URIs and PackageInstaller API. The UriForwardProxy enables accessing content from different profiles. The installation callback handles success, system app restrictions, and failure scenarios with appropriate user feedback. ```java // Install APK from main profile to work profile Uri apkUri = Uri.parse("content://com.example/apk/myapp.apk"); UriForwardProxy proxy = new UriForwardProxy(context, apkUri); mServiceWork.installApk(proxy, new IAppInstallCallback.Stub() { @Override public void callback(int resultCode) { if (resultCode == Activity.RESULT_OK) { Toast.makeText(context, "Installation successful", Toast.LENGTH_SHORT).show(); } else if (resultCode == ShelterService.RESULT_CANNOT_INSTALL_SYSTEM_APP) { Toast.makeText(context, "Cannot install system app", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, "Installation failed", Toast.LENGTH_SHORT).show(); } } }); ``` -------------------------------- ### Work Profile Provisioning and Setup (Java) Source: https://context7.com/petercxy/shelter/llms.txt Provisions a new work profile and configures it as a managed profile with device admin privileges. It uses `DevicePolicyManager` to set up cross-profile intent filters and enforce user restrictions. ```java // Initiate work profile provisioning (Android 7.0+) Intent provisionIntent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE); provisionIntent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, new ComponentName(context, ShelterDeviceAdminReceiver.class)); provisionIntent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION, true); startActivityForResult(provisionIntent, REQUEST_PROVISION); // After provisioning, finalize setup in work profile Utility.enforceWorkProfilePolicies(context); Utility.enforceUserRestrictions(context); // Configure cross-profile intent filters DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); ComponentName admin = new ComponentName(context, ShelterDeviceAdminReceiver.class); // Allow specific intents to cross profile boundary dpm.addCrossProfileIntentFilter(admin, new IntentFilter(DummyActivity.START_SERVICE), DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT); // Enable profile dpm.setProfileEnabled(admin); ``` -------------------------------- ### Android Local Storage Manager - Cross-Profile Settings Sync Source: https://context7.com/petercxy/shelter/llms.txt Shows how to initialize and use LocalStorageManager for persisting settings between main and work profiles. Demonstrates string list storage for auto-freeze app lists, boolean preference synchronization via intents, and setup completion flag management. Requires DummyActivity.SYNCHRONIZE_PREFERENCE intent action for profile boundary transfer. ```java // Initialize storage (in Application.onCreate) LocalStorageManager.initialize(context); LocalStorageManager storage = LocalStorageManager.getInstance(); // Store auto-freeze app list String[] frozenApps = {"com.facebook.katana", "com.instagram.android"}; storage.setStringList(LocalStorageManager.PREF_AUTO_FREEZE_LIST_WORK_PROFILE, frozenApps); // Check if app is in auto-freeze list boolean shouldFreeze = storage.stringListContains( LocalStorageManager.PREF_AUTO_FREEZE_LIST_WORK_PROFILE, "com.facebook.katana"); // Synchronize boolean preference to work profile Intent syncIntent = new Intent(DummyActivity.SYNCHRONIZE_PREFERENCE); syncIntent.putExtra("name", "skip_foreground_freeze"); syncIntent.putExtra("boolean", true); Utility.transferIntentToProfile(context, syncIntent); startActivity(syncIntent); // Setup completion flags storage.setBoolean(LocalStorageManager.PREF_HAS_SETUP, true); storage.setBoolean(LocalStorageManager.PREF_IS_SETTING_UP, false); ``` -------------------------------- ### Android Parcelable App Metadata Wrapper - Retrieve and Transfer Source: https://context7.com/petercxy/shelter/llms.txt Demonstrates retrieving installed application metadata using PackageManager and wrapping it in a custom AIDL parcelable wrapper for cross-profile data transfer. Uses ApplicationInfoWrapper with ILoadIconCallback for asynchronous icon loading and includes filtering and sorting operations for app management. ```java // Get installed apps with metadata PackageManager pm = context.getPackageManager(); List apps = pm.getInstalledApplications( PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_UNINSTALLED_PACKAGES); // Wrap and filter apps List wrappedApps = apps.stream() .filter(info -> !info.packageName.equals(context.getPackageName())) .filter(info -> (info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) .map(ApplicationInfoWrapper::new) .map(wrapper -> wrapper.loadLabel(pm).setHidden(isHidden(wrapper.getPackageName()))) .sorted((a, b) -> a.getLabel().compareTo(b.getLabel())) .collect(Collectors.toList()); // Load app icon asynchronously ApplicationInfoWrapper app = wrappedApps.get(0); mService.loadIcon(app, new ILoadIconCallback.Stub() { @Override public void callback(Bitmap icon) { // Display icon imageView.setImageBitmap(icon); } }); ``` -------------------------------- ### File Shuttle Service for Cross-Profile File Access (Java) Source: https://context7.com/petercxy/shelter/llms.txt Provides file access between profiles by implementing a `DocumentsProvider` interface backed by an `IFileShuttleService`. This allows listing files, opening files for reading, and creating new files across profiles. ```java // Bind to FileShuttleService in work profile ((ShelterApplication) getApplication()).bindFileShuttleService(new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { IFileShuttleService shuttle = IFileShuttleService.Stub.asInterface(service); // List files in directory String path = Environment.getExternalStorageDirectory().getAbsolutePath(); List> files = shuttle.loadFiles(path); for (Map file : files) { String name = (String) file.get(DocumentsContract.Document.COLUMN_DISPLAY_NAME); String mimeType = (String) file.get(DocumentsContract.Document.COLUMN_MIME_TYPE); Long size = (Long) file.get(DocumentsContract.Document.COLUMN_SIZE); Log.d("Shelter", String.format("%s (%s): %d bytes", name, mimeType, size)); } // Open file for reading ParcelFileDescriptor pfd = shuttle.openFile(path + "/document.pdf", "r"); // Use pfd for reading... // Create new file String newFilePath = shuttle.createFile(path, "text/plain", "notes.txt"); } @Override public void onServiceDisconnected(ComponentName name) {} }); ``` -------------------------------- ### Android Batch Freeze Management - All Apps Auto-Freeze Workflow Source: https://context7.com/petercxy/shelter/llms.txt Implements batch freezing functionality for all apps in the auto-freeze list simultaneously. Creates a launcher shortcut for quick privacy protection and demonstrates the complete workflow from shortcut creation to actual app freezing using DevicePolicyManager.setApplicationHidden across profile boundaries. Uses FREEZE_ALL_IN_LIST intent action for work profile processing. ```java // Create batch freeze shortcut Intent freezeIntent = new Intent(DummyActivity.PUBLIC_FREEZE_ALL); freezeIntent.setComponent(new ComponentName(context, DummyActivity.class)); freezeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); Utility.createLauncherShortcut(context, freezeIntent, Icon.createWithResource(context, R.mipmap.ic_freeze), "shelter-freeze-all", "Freeze All"); // When launched, loads auto-freeze list and freezes all apps // Implementation in DummyActivity: String[] list = LocalStorageManager.getInstance() .getStringList(LocalStorageManager.PREF_AUTO_FREEZE_LIST_WORK_PROFILE); Intent workIntent = new Intent(FREEZE_ALL_IN_LIST); workIntent.putExtra("list", list); Utility.transferIntentToProfile(context, workIntent); startActivity(workIntent); // In work profile, DummyActivity freezes each app: for (String pkg : list) { dpm.setApplicationHidden(adminComponent, pkg, true); } ``` -------------------------------- ### Binding to ShelterService Source: https://context7.com/petercxy/shelter/llms.txt Demonstrates how to bind to the ShelterService from the main profile using AIDL interface. This enables communication with the service that manages apps across both main and work profiles. The service connection handles both successful binding and disconnection scenarios while retrieving the list of non-system applications. ```java // Binding to ShelterService from main profile ShelterApplication app = (ShelterApplication) getApplication(); app.bindShelterService(new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { IShelterService shelterService = IShelterService.Stub.asInterface(service); // Get list of apps in profile shelterService.getApps(new IGetAppsCallback.Stub() { @Override public void callback(List apps) { // Process app list for (ApplicationInfoWrapper app : apps) { Log.d("Shelter", "App: " + app.getPackageName()); } } }, false); // false = hide system apps } @Override public void onServiceDisconnected(ComponentName name) { // Handle disconnection } }, false); // false = not foreground service ``` -------------------------------- ### Creating Auto-Freeze Launcher Source: https://context7.com/petercxy/shelter/llms.txt Shows how to create launcher shortcuts that unfreeze and launch frozen apps, with automatic re-freezing when the screen locks. This feature is useful for privacy-invasive applications. The implementation checks an auto-freeze list to determine which apps should be automatically re-frozen, creating personalized launcher shortcuts with appropriate icons and labels. ```java // Create launcher shortcut that unfreezes and launches app Intent launchIntent = new Intent(DummyActivity.PUBLIC_UNFREEZE_AND_LAUNCH); launchIntent.setComponent(new ComponentName(context, DummyActivity.class)); launchIntent.putExtra("packageName", "com.example.app"); // The app will be automatically registered for freeze-on-screen-lock // if it's in the auto-freeze list String[] autoFreezeList = LocalStorageManager.getInstance() .getStringList(LocalStorageManager.PREF_AUTO_FREEZE_LIST_WORK_PROFILE); boolean shouldAutoFreeze = Arrays.asList(autoFreezeList).contains("com.example.app"); Icon icon = Icon.createWithResource(context, R.mipmap.ic_launcher); Utility.createLauncherShortcut(context, launchIntent, icon, "unfreeze-app-id", "Launch App"); ``` -------------------------------- ### Managing App Freezing Source: https://context7.com/petercxy/shelter/llms.txt Demonstrates how to freeze and unfreeze applications using DevicePolicyManager to prevent them from running in the background or being launched. This functionality requires profile owner privileges. The code shows the complete flow of hiding apps, unhiding them, and checking their current frozen state for privacy management. ```java // Freeze an app in work profile (requires profile owner) DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); ComponentName adminComponent = new ComponentName(context, ShelterDeviceAdminReceiver.class); ApplicationInfoWrapper app = new ApplicationInfoWrapper(appInfo); // Freeze the app mServiceWork.freezeApp(app); // This calls: dpm.setApplicationHidden(adminComponent, packageName, true); // Unfreeze the app mServiceWork.unfreezeApp(app); // This calls: dpm.setApplicationHidden(adminComponent, packageName, false); // Check if app is frozen boolean isHidden = dpm.isApplicationHidden(adminComponent, packageName); ``` -------------------------------- ### Cross-Profile Widget Providers (Java) Source: https://context7.com/petercxy/shelter/llms.txt Enables widgets from work profile apps to be displayed on the main profile's home screen. It involves retrieving a list of enabled widget providers and enabling or disabling them for specific packages. ```java // Get list of enabled widget providers IShelterService serviceWork = ...; // from work profile List enabledProviders = serviceWork.getCrossProfileWidgetProviders(); // Enable widget provider for an app String packageName = "com.example.app"; boolean success = serviceWork.setCrossProfileWidgetProviderEnabled(packageName, true); if (success) { // Widget provider enabled // User can now add widgets from this app to main profile launcher } // Disable widget provider serviceWork.setCrossProfileWidgetProviderEnabled(packageName, false); ``` -------------------------------- ### Cross-Profile Intent Transfer (Java) Source: https://context7.com/petercxy/shelter/llms.txt Transfers intents from the main profile to the work profile using authentication via digital signatures. The `transferIntentToProfile` method handles signing, and the receiving activity in the work profile verifies the signature. ```java // Send intent to work profile with authentication Intent intent = new Intent(DummyActivity.START_SERVICE); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Transfer intent to work profile (adds signature) Utility.transferIntentToProfile(context, intent); // This finds the corresponding activity in work profile and signs the intent // Launch the intent startActivity(intent); // In work profile, DummyActivity verifies signature before processing if (!AuthenticationUtility.checkIntent(intent)) { // Unauthenticated request - reject finish(); return; } ``` -------------------------------- ### Auto-Freeze Service on Screen Lock (Java) Source: https://context7.com/petercxy/shelter/llms.txt Registers an application to be frozen when the screen locks, with configurable delay and an option to skip foreground apps. The service listens for screen lock (ACTION_SCREEN_OFF) and unlock (ACTION_SCREEN_ON) broadcasts. ```java // Register app to be frozen when screen locks FreezeService.registerAppToFreeze("com.example.app"); context.startService(new Intent(context, FreezeService.class)); // Configure auto-freeze delay (in settings) SettingsManager.getInstance().setAutoFreezeDelay(5); // 5 seconds // Enable skip foreground apps feature SettingsManager.getInstance().setSkipForegroundEnabled(true); // When screen locks, FreezeService receives ACTION_SCREEN_OFF broadcast // After delay, it freezes all registered apps except foreground apps // If screen unlocks before delay (ACTION_SCREEN_ON), freeze is canceled ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.