package app.grapheneos.setupwizard.view.activity import android.os.Bundle import android.os.Handler import android.os.Looper import android.view.View import android.view.WindowManager import android.widget.Button import android.content.Context import android.app.admin.DevicePolicyManager import app.grapheneos.setupwizard.R import app.grapheneos.setupwizard.action.FinishActions import com.android.secureline.ISecureLineManager class FinishActivity : SetupWizardActivity( R.layout.activity_finish_secureline, R.drawable.baseline_done_all_glif, R.string.sl_finish_title, R.string.sl_finish_body ) { private lateinit var finishButton: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Keep the final LemenzoOS screen visually consistent with the // other branded setup screens. Provisioning logic is unchanged. window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) window.statusBarColor = getColor(R.color.secureline_background) window.navigationBarColor = getColor(R.color.secureline_background) window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN // 🔒 Block gesture back (Android 13+) if (android.os.Build.VERSION.SDK_INT >= 33) { onBackInvokedDispatcher.registerOnBackInvokedCallback( android.window.OnBackInvokedDispatcher.PRIORITY_OVERLAY ) { // fully ignore back gesture } } } override fun bindViews() { finishButton = findViewById(R.id.primary_button) finishButton.setText(R.string.sl_finish_enter) } override fun onBackPressed() { // 🔒 Block hardware/software back } override fun setupActions() { finishButton.setOnClickListener { /* finish setupwizard sets: device_provisioned = 1 user_setup_complete = 1 */ FinishActions.finish(this, false) /* Let system handle transition (CRITICAL FIX) Force lock → triggers proper launcher start */ Handler(Looper.getMainLooper()) .postDelayed({ try { val dpm = getSystemService( Context.DEVICE_POLICY_SERVICE ) as DevicePolicyManager dpm.lockNow() } catch (e: Exception) { e.printStackTrace() } }, 300) /* notify SecureLine after provisioning */ Handler(Looper.getMainLooper()) .postDelayed({ try { val sm = ISecureLineManager.Stub.asInterface( android.os.ServiceManager.getService("secureline") ) sm?.notifyDeviceUnlocked() } catch (e: Exception) { e.printStackTrace() } }, 1500) } } }