mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-19 20:44:22 +01:00
The decision layer needed a runtime. A polling loop was the obvious design and the wrong one: Doze can skip a poll indefinitely, and skipping the 05:00 boundary leaves the curfew allowlist applied into the morning -- the user finds their banking app missing with no obvious cause. The transitions are known ahead of time, so they get exact alarms. The service wakes, applies, schedules the next run and stops rather than sitting resident. BootReceiver takes LOCKED_BOOT_COMPLETED as well as BOOT_COMPLETED, because the latter does not arrive until first unlock. That is not theoretical: this phone sat at RUNNING_LOCKED for minutes after an earlier reboot in this session, with no network and no app able to start. Relying on BOOT_COMPLETED alone freezes enforcement state across a reboot -- safe for hiding, not for unhiding, which is the direction that strands you without a dialer. The schedule is re-armed before unlock; the pass itself waits until storage is readable. The first on-device run logged "exact alarms not permitted", and dumpsys showed what that costs: window=+11m14s, maxWhenElapsed=+25m51s, so a 15-minute fallback could slip to 26 minutes. SCHEDULE_EXACT_ALARM is user-revocable and denied by default on Android 16; USE_EXACT_ALARM is the permission for apps whose function is acting at specific times, and is granted at install. After the change: window=0, exactAllowReason=policy_permission, whenElapsed equal to maxWhenElapsed. The service reports "not DO/PO - no enforcement applied" and does nothing when unprovisioned, rather than failing quietly, and a failure inside a pass cannot stop the next run being scheduled -- an enforcement bug should degrade one tick, not end the chain. Not yet wired: the service logs a tick rather than calling setApplicationHidden with the decision. Both halves are tested; joining them is next. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AwepyL5Lxs5QKbKkMpxxxL
108 lines
5.4 KiB
XML
108 lines
5.4 KiB
XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
<!-- USE_EXACT_ALARM rather than SCHEDULE_EXACT_ALARM: the latter is
|
|
user-revocable and was observed denied by default on Android 16,
|
|
which turned a curfew boundary into a +26 minute window. This app's
|
|
whole function is acting at specific times, which is the documented
|
|
qualifying use, and it is granted at install with no runtime prompt. -->
|
|
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
|
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
<!-- Coarse is enough for a 150 m geofence and is the cheaper grant to ask
|
|
for; background access is what makes the gate work while the screen is
|
|
off, and is requested separately at runtime. -->
|
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
|
<!-- Needed to enumerate installed packages for the allowlist sweep. -->
|
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
|
<application
|
|
android:label="focus_owner"
|
|
android:name="${applicationName}"
|
|
android:icon="@mipmap/ic_launcher">
|
|
<activity
|
|
android:name=".MainActivity"
|
|
android:exported="true"
|
|
android:launchMode="singleTop"
|
|
android:taskAffinity=""
|
|
android:theme="@style/LaunchTheme"
|
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
|
android:hardwareAccelerated="true"
|
|
android:windowSoftInputMode="adjustResize">
|
|
<!-- Specifies an Android theme to apply to this Activity as soon as
|
|
the Android process has started. This theme is visible to the user
|
|
while the Flutter UI initializes. After that, this theme continues
|
|
to determine the Window background behind the Flutter UI. -->
|
|
<meta-data
|
|
android:name="io.flutter.embedding.android.NormalTheme"
|
|
android:resource="@style/NormalTheme"
|
|
/>
|
|
<intent-filter>
|
|
<action android:name="android.intent.action.MAIN"/>
|
|
<category android:name="android.intent.category.LAUNCHER"/>
|
|
</intent-filter>
|
|
</activity>
|
|
<!-- Device admin component. Declaring it makes device-owner
|
|
provisioning possible; it applies no restrictions on its own.
|
|
BIND_DEVICE_ADMIN must be held by the system, and the receiver must
|
|
be exported, or `dpm set-device-owner` cannot find it. -->
|
|
<receiver
|
|
android:name=".FocusDeviceAdminReceiver"
|
|
android:exported="true"
|
|
android:permission="android.permission.BIND_DEVICE_ADMIN">
|
|
<meta-data
|
|
android:name="android.app.device_admin"
|
|
android:resource="@xml/device_admin" />
|
|
<intent-filter>
|
|
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
|
</intent-filter>
|
|
</receiver>
|
|
|
|
<!-- Applies one enforcement pass, then schedules the next. Not
|
|
resident: the alarm brings it back. -->
|
|
<service
|
|
android:name=".EnforcementService"
|
|
android:exported="false"
|
|
android:foregroundServiceType="specialUse">
|
|
<property
|
|
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
|
android:value="Applies the device-owner focus policy at scheduled times" />
|
|
</service>
|
|
|
|
<receiver
|
|
android:name=".EnforcementAlarmReceiver"
|
|
android:exported="false" />
|
|
|
|
<!-- directBootAware so LOCKED_BOOT_COMPLETED can re-arm the schedule
|
|
before the user unlocks; BOOT_COMPLETED alone does not arrive
|
|
until first unlock. -->
|
|
<receiver
|
|
android:name=".BootReceiver"
|
|
android:directBootAware="true"
|
|
android:enabled="true"
|
|
android:exported="true">
|
|
<intent-filter>
|
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
|
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
|
</intent-filter>
|
|
</receiver>
|
|
|
|
<!-- Don't delete the meta-data below.
|
|
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
|
<meta-data
|
|
android:name="flutterEmbedding"
|
|
android:value="2" />
|
|
</application>
|
|
<!-- Required to query activities that can process text, see:
|
|
https://developer.android.com/training/package-visibility and
|
|
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
|
|
|
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
|
<queries>
|
|
<intent>
|
|
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
|
<data android:mimeType="text/plain"/>
|
|
</intent>
|
|
</queries>
|
|
</manifest>
|