1 /* 2 * Copyright (C) 2019 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.android.settings.wifi.slice; 18 19 import android.content.Context; 20 import android.net.Uri; 21 import android.os.SystemClock; 22 23 import com.android.settings.slices.SliceBackgroundWorker; 24 25 /** 26 * {@link SliceBackgroundWorker} for Wi-Fi, used by {@link ContextualWifiSlice}. 27 */ 28 public class ContextualWifiScanWorker extends WifiScanWorker { 29 30 private static long sVisibleUiSessionToken; 31 private static long sActiveSession; 32 ContextualWifiScanWorker(Context context, Uri uri)33 public ContextualWifiScanWorker(Context context, Uri uri) { 34 super(context, uri); 35 } 36 37 /** 38 * Starts a new visible UI session for the purpose of automatically starting captive portal. 39 * 40 * A visible UI session is defined as a duration of time when a UI screen is visible to user. 41 * Going to a sub-page and coming out breaks the continuation, leaving the page and coming back 42 * breaks it too. 43 */ newVisibleUiSession()44 public static void newVisibleUiSession() { 45 sVisibleUiSessionToken = SystemClock.elapsedRealtime(); 46 } 47 saveSession()48 static void saveSession() { 49 sActiveSession = sVisibleUiSessionToken; 50 } 51 52 @Override clearClickedWifiOnSliceUnpinned()53 protected void clearClickedWifiOnSliceUnpinned() { 54 // Do nothing for contextual Wi-Fi slice 55 } 56 57 @Override isSessionValid()58 protected boolean isSessionValid() { 59 if (sVisibleUiSessionToken != sActiveSession) { 60 clearClickedWifi(); 61 return false; 62 } 63 return true; 64 } 65 66 @Override getApRowCount()67 protected int getApRowCount() { 68 return ContextualWifiSlice.getApRowCount(); 69 } 70 }