Daniel Sandler | 50a5313 | 2012-10-24 15:02:27 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
John Spurlock | 48f37ec | 2012-10-05 16:32:51 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar.policy; |
| 18 | |
| 19 | import android.app.ActivityManager; |
| 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
| 24 | |
| 25 | public class CurrentUserTracker extends BroadcastReceiver { |
| 26 | |
| 27 | private int mCurrentUserId; |
| 28 | |
| 29 | public CurrentUserTracker(Context context) { |
| 30 | IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 31 | context.registerReceiver(this, filter); |
| 32 | mCurrentUserId = ActivityManager.getCurrentUser(); |
| 33 | } |
| 34 | |
| 35 | public int getCurrentUserId() { |
| 36 | return mCurrentUserId; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void onReceive(Context context, Intent intent) { |
| 41 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 42 | mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); |
| 43 | } |
| 44 | } |
| 45 | } |