Home | History | Annotate | Download | only in receiver
      1 /*
      2  * Copyright (C) 2017 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 android.inputmethodservice.cts.receiver;
     18 
     19 import static android.inputmethodservice.cts.common.DeviceEventConstants.EXTRA_EVENT_TIME;
     20 
     21 import android.content.BroadcastReceiver;
     22 import android.content.ContentValues;
     23 import android.content.Context;
     24 import android.content.Intent;
     25 import android.inputmethodservice.cts.DeviceEvent;
     26 import android.inputmethodservice.cts.common.EventProviderConstants.EventTableConstants;
     27 import android.net.Uri;
     28 import android.os.SystemClock;
     29 import android.util.Log;
     30 
     31 public final class EventReceiver extends BroadcastReceiver {
     32 
     33     private static final String TAG = EventReceiver.class.getSimpleName();
     34     private static final boolean DEBUG = false;
     35 
     36     private static final Uri CONTENT_URI = Uri.parse(EventTableConstants.CONTENT_URI);
     37 
     38     @Override
     39     public void onReceive(final Context context, final Intent intent) {
     40         // Since {@code intent} which comes from host has no
     41         // {@link DeviceEventConstants#EXTRA_EVENT_TIME EXTRA_EVENT_TIME} extra, here we record the
     42         // time.
     43         if (!intent.hasExtra(EXTRA_EVENT_TIME)) {
     44             intent.putExtra(EXTRA_EVENT_TIME, SystemClock.uptimeMillis());
     45         }
     46         final DeviceEvent event = DeviceEvent.newEvent(intent);
     47         if (DEBUG) {
     48             Log.d(TAG, "onReceive: event=" + event);
     49         }
     50         final ContentValues values = DeviceEvent.buildContentValues(event);
     51         context.getContentResolver().insert(CONTENT_URI, values);
     52     }
     53 }
     54