• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.android.iwlan;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.ContentProvider;
22 import android.content.ContentValues;
23 import android.content.Context;
24 import android.database.Cursor;
25 import android.net.Uri;
26 import android.os.Bundle;
27 import android.os.Handler;
28 import android.os.HandlerThread;
29 import android.util.Log;
30 
31 import com.google.android.iwlan.epdg.EpdgTunnelManager;
32 import com.google.android.iwlan.flags.FeatureFlags;
33 import com.google.android.iwlan.flags.FeatureFlagsImpl;
34 
35 public class IwlanSilentRestart extends ContentProvider {
36     private static final String TAG = IwlanSilentRestart.class.getSimpleName();
37 
38     private static final String METHOD_RESTART_IWLAN = "restart_iwlan";
39 
40     private static final String PERMISSION_RESTART_IWLAN = "android.iwlan.permission.RESTART_IWLAN";
41 
42     private final FeatureFlags mFeatureFlags = new FeatureFlagsImpl();
43     private Handler mHandler;
44 
45     @Override
onCreate()46     public boolean onCreate() {
47         Log.d(TAG, "onCreate");
48         if (!mFeatureFlags.iwlanSilentRestart()) {
49             Log.d(TAG, "feature not available");
50             return false;
51         }
52 
53         HandlerThread handlerThread = new HandlerThread("IwlanSilentRestartThread");
54         handlerThread.start();
55         mHandler = new Handler(handlerThread.getLooper());
56 
57         return true;
58     }
59 
clearAndExit()60     private void clearAndExit() {
61         deinitService();
62         Log.i(TAG, "Restart com.google.pixel.iwlan by killing it");
63         System.exit(0);
64     }
65 
deinitService()66     private void deinitService() {
67         EpdgTunnelManager.deinit();
68     }
69 
70     @Override
call( @onNull String authority, @NonNull String method, @Nullable String arg, @Nullable Bundle extras)71     public @Nullable Bundle call(
72             @NonNull String authority,
73             @NonNull String method,
74             @Nullable String arg,
75             @Nullable Bundle extras) {
76         Log.d(TAG, "called " + authority + " " + method);
77 
78         if (METHOD_RESTART_IWLAN.equals(method)) {
79             final Context context = getContext();
80             if (context == null) {
81                 Log.d(TAG, "Cannot find context from the content provider");
82                 return null;
83             }
84 
85             context.enforceCallingOrSelfPermission(PERMISSION_RESTART_IWLAN, null);
86             Log.i(TAG, "Restart com.google.android.iwlan");
87 
88             mHandler.post(this::clearAndExit);
89         }
90 
91         return null;
92     }
93 
94     @Override
query( @onNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder)95     public @Nullable Cursor query(
96             @NonNull Uri uri,
97             @Nullable String[] projection,
98             @Nullable String selection,
99             @Nullable String[] selectionArgs,
100             @Nullable String sortOrder) {
101         throw new UnsupportedOperationException();
102     }
103 
104     @Override
getType(@onNull Uri uri)105     public @Nullable String getType(@NonNull Uri uri) {
106         throw new UnsupportedOperationException();
107     }
108 
109     @Override
insert(@onNull Uri uri, @Nullable ContentValues values)110     public @Nullable Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
111         throw new UnsupportedOperationException();
112     }
113 
114     @Override
delete( @onNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs)115     public int delete(
116             @NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
117         throw new UnsupportedOperationException();
118     }
119 
120     @Override
update( @onNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs)121     public int update(
122             @NonNull Uri uri,
123             @Nullable ContentValues values,
124             @Nullable String selection,
125             @Nullable String[] selectionArgs) {
126         throw new UnsupportedOperationException();
127     }
128 }
129