Ejemplo n.º 1
0
ECode DataConnectionStats::StartMonitoring()
{
    AutoPtr<IInterface> obj;
    mContext->GetSystemService(IContext::TELEPHONY_SERVICE, (IInterface**)&obj);
    AutoPtr<ITelephonyManager> phone = ITelephonyManager::Probe(obj);
    if (phone != NULL) {
        phone->Listen(mPhoneStateListener,
                IPhoneStateListener::LISTEN_SERVICE_STATE
                | IPhoneStateListener::LISTEN_SIGNAL_STRENGTHS
                | IPhoneStateListener::LISTEN_DATA_CONNECTION_STATE
                | IPhoneStateListener::LISTEN_DATA_ACTIVITY);
    }
    else {
        Logger::E(TAG, "TELEPHONY_SERVICE is not ok");
        return E_NOT_IMPLEMENTED;
    }

    AutoPtr<IIntentFilter> filter;
    CIntentFilter::New((IIntentFilter**)&filter);
    filter->AddAction(ITelephonyIntents::ACTION_SIM_STATE_CHANGED);
    filter->AddAction(IConnectivityManager::CONNECTIVITY_ACTION);
    filter->AddAction(IConnectivityManager::INET_CONDITION_ACTION);
    AutoPtr<IIntent> intent;
    mContext->RegisterReceiver(this, filter, (IIntent**)&intent);
    return NOERROR;
}
Ejemplo n.º 2
0
ECode TwilightService::OnStart()
{
    mUpdateLocationReceiver = new UpdateLocationReceiver(this);
    mEmptyLocationListener = new EmptyLocationListener();
    mLocationListener = new MyLocationListener(this);

    AutoPtr<IContext> context;
    GetContext((IContext**)&context);
    AutoPtr<IInterface> service;
    context->GetSystemService(IContext::ALARM_SERVICE, (IInterface**)&service);
    mAlarmManager = IAlarmManager::Probe(service);
    service = NULL;
    context->GetSystemService(IContext::LOCATION_SERVICE, (IInterface**)&service);
    mLocationManager = ILocationManager::Probe(service);
    mLocationHandler = new LocationHandler(this);

    AutoPtr<IIntentFilter> filter;
    CIntentFilter::New(IIntent::ACTION_AIRPLANE_MODE_CHANGED,(IIntentFilter**)&filter);
    filter->AddAction(IIntent::ACTION_TIME_CHANGED);
    filter->AddAction(IIntent::ACTION_TIMEZONE_CHANGED);
    filter->AddAction(ACTION_UPDATE_TWILIGHT_STATE);
    AutoPtr<IIntent> intent;
    context->RegisterReceiver((IBroadcastReceiver*)mUpdateLocationReceiver, filter, (IIntent**)&intent);

    PublishLocalService(EIID_ITwilightManager, mService);
    return NOERROR;
}
Ejemplo n.º 3
0
ECode AdapterViewFlipper::OnAttachedToWindow()
{
    // ==================before translated======================
    // super.onAttachedToWindow();
    //
    // // Listen for broadcasts related to user-presence
    // final IntentFilter filter = new IntentFilter();
    // filter.addAction(Intent.ACTION_SCREEN_OFF);
    // filter.addAction(Intent.ACTION_USER_PRESENT);
    //
    // // OK, this is gross but needed. This class is supported by the
    // // remote views machanism and as a part of that the remote views
    // // can be inflated by a context for another user without the app
    // // having interact users permission - just for loading resources.
    // // For exmaple, when adding widgets from a user profile to the
    // // home screen. Therefore, we register the receiver as the current
    // // user not the one the context is for.
    // getContext().registerReceiverAsUser(mReceiver, android.os.Process.myUserHandle(),
    //         filter, null, mHandler);
    //
    //
    // if (mAutoStart) {
    //     // Automatically start when requested
    //     startFlipping();
    // }

    AdapterViewAnimator::OnAttachedToWindow();
    // Listen for broadcasts related to user-presence
    AutoPtr<IIntentFilter> filter;
    CIntentFilter::New((IIntentFilter**)&filter);
    filter->AddAction(IIntent::ACTION_SCREEN_OFF);
    filter->AddAction(IIntent::ACTION_USER_PRESENT);

    // OK, this is gross but needed. This class is supported by the
    // remote views machanism and as a part of that the remote views
    // can be inflated by a context for another user without the app
    // having interact users permission - just for loading resources.
    // For exmaple, when adding widgets from a user profile to the
    // home screen. Therefore, we register the receiver as the current
    // user not the one the context is for.
    AutoPtr<IContext> context;
    GetContext((IContext**)&context);
    AutoPtr<IUserHandle> userHandle;
    Process::MyUserHandle((IUserHandle**)&userHandle);
    AutoPtr<IIntent> intent;
    context->RegisterReceiverAsUser(mReceiver, userHandle, filter, String(""), mHandler, (IIntent**)&intent);

    if (mAutoStart) {
        // Automatically start when requested
        StartFlipping();
    }
    return NOERROR;
}
Ejemplo n.º 4
0
ECode CPowerUI::Receiver::Init()
{
    // Register for Intent broadcasts for...
    AutoPtr<IIntentFilter> filter;
    CIntentFilter::New((IIntentFilter**)&filter);
    filter->AddAction(IIntent::ACTION_BATTERY_CHANGED);
    filter->AddAction(IIntent::ACTION_SCREEN_OFF);
    filter->AddAction(IIntent::ACTION_SCREEN_ON);
    filter->AddAction(IPowerManager::ACTION_POWER_SAVE_MODE_CHANGING);
    filter->AddAction(IPowerManager::ACTION_POWER_SAVE_MODE_CHANGED);
    AutoPtr<IIntent> i;
    mHost->mContext->RegisterReceiver(this, filter, String(NULL), mHost->mHandler, (IIntent**)&i);
    UpdateSaverMode();
    return NOERROR;
}
Ejemplo n.º 5
0
ECode RegisteredServicesCache::constructor(
    /* [in] */ IContext* context,
    /* [in] */ const String& interfaceName,
    /* [in] */ const String& metaDataName,
    /* [in] */ const String& attributeName,
    /* [in] */ IXmlSerializerAndParser* serializerAndParser)
{
    mContext = context;
    mInterfaceName = interfaceName;
    mMetaDataName = metaDataName;
    mAttributesName = attributeName;
    mSerializerAndParser = serializerAndParser;

    mPackageReceiver = (IBroadcastReceiver*)new RegisteredServicesCache::PackageReceiver(this);
    mPackageReceiver = (IBroadcastReceiver*)new RegisteredServicesCache::ExternalReceiver(this);

    AutoPtr<IEnvironment> env;
    CEnvironment::AcquireSingleton((IEnvironment**)&env);
    AutoPtr<IFile> dataDir;
    env->GetDataDirectory((IFile**)&dataDir);
    AutoPtr<IFile> systemDir, syncDir, interFile;
    CFile::New(dataDir, String("system"), (IFile**)&systemDir);
    CFile::New(systemDir, String("registered_services"), (IFile**)&syncDir);
    CFile::New(syncDir, interfaceName + String(".xml"), (IFile**)&interFile);
    CAtomicFile::New(interFile, (IAtomicFile**)&mPersistentServicesFile);

    // Load persisted services from disk
    ReadPersistentServicesLocked();

    AutoPtr<IIntentFilter> intentFilter;
    CIntentFilter::New((IIntentFilter**)&intentFilter);
    intentFilter->AddAction(IIntent::ACTION_PACKAGE_ADDED);
    intentFilter->AddAction(IIntent::ACTION_PACKAGE_CHANGED);
    intentFilter->AddAction(IIntent::ACTION_PACKAGE_REMOVED);
    intentFilter->AddDataScheme(String("package"));
    AutoPtr<IIntent> intent;
    mContext->RegisterReceiverAsUser(mPackageReceiver, UserHandle::ALL, intentFilter, String(NULL), NULL, (IIntent**)&intent);

    // Register for events related to sdcard installation.
    AutoPtr<IIntentFilter> sdFilter;
    CIntentFilter::New((IIntentFilter**)&sdFilter);
    sdFilter->AddAction(IIntent::ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter->AddAction(IIntent::ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    intent = NULL;
    mContext->RegisterReceiver(mExternalReceiver, sdFilter, (IIntent**)&intent);
    return NOERROR;
}
Ejemplo n.º 6
0
ECode ViewFlipper::OnAttachedToWindow()
{
    ViewAnimator::OnAttachedToWindow();

    // Listen for broadcasts related to user-presence
    AutoPtr<IIntentFilter> filter;
    CIntentFilter::New((IIntentFilter**)&filter);
    filter->AddAction(IIntent::ACTION_SCREEN_OFF);
    filter->AddAction(IIntent::ACTION_USER_PRESENT);
    AutoPtr<IIntent> intent;
    GetContext()->RegisterReceiver(mReceiver, filter, (IIntent**)&intent);

    if (mAutoStart) {
        // Automatically start when requested
        StartFlipping();
    }
    return NOERROR;
}
Ejemplo n.º 7
0
ECode CSplitClockView::OnAttachedToWindow()
{
    LinearLayout::OnAttachedToWindow();

    AutoPtr<IIntentFilter> filter;
    CIntentFilter::New((IIntentFilter**)&filter);
    filter->AddAction(IIntent::ACTION_TIME_CHANGED);
    filter->AddAction(IIntent::ACTION_TIMEZONE_CHANGED);
    filter->AddAction(IIntent::ACTION_LOCALE_CHANGED);

    AutoPtr<IContext> context;
    GetContext((IContext**)&context);
    AutoPtr<IIntent> i;
    context->RegisterReceiver(mIntentReceiver, filter, String(NULL), NULL, (IIntent**)&i);

    UpdatePatterns();
    return NOERROR;
}
ECode ProfileManagerService::constructor(
    /* [in] */ IContext* context)
{
    mContext = context;
    assert(0 && "TODO");
    // CBackupManager::New(mContext.Get(), (IBackupManager**)&mBackupManager);
    mTriggerHelper = new ProfileTriggerHelper(mContext, this);
    String str;
    context->GetString(R::string::wildcardProfile, &str);
    CNotificationGroup::New(str, R::string::wildcardProfile, mWildcardUUID, (INotificationGroup**)&mWildcardGroup);
    Initialize();
    AutoPtr<IIntentFilter> filter;
    CIntentFilter::New((IIntentFilter**)&filter);
    filter->AddAction(IIntent::ACTION_LOCALE_CHANGED);
    filter->AddAction(IIntent::ACTION_SHUTDOWN);
    mIntentReceiver = new MyBroadcastReceiver(this);
    AutoPtr<IIntent> intent;
    return mContext->RegisterReceiver(mIntentReceiver.Get(), filter.Get(), (IIntent**)&intent);
}
ECode RestrictedSettingsFragment::OnCreate(
    /* [in] */ IBundle* icicle)
{
    SettingsPreferenceFragment::OnCreate(icicle);

    AutoPtr<IInterface> obj = GetSystemService(IContext::RESTRICTIONS_SERVICE);
    mRestrictionsManager = IRestrictionsManager::Probe(obj);
    obj = GetSystemService(IContext::USER_SERVICE);
    mUserManager = IUserManager::Probe(obj);

    if (icicle != NULL) {
        icicle->GetBoolean(KEY_CHALLENGE_SUCCEEDED, FALSE, &mChallengeSucceeded);
        icicle->GetBoolean(KEY_CHALLENGE_REQUESTED, FALSE, &mChallengeRequested);
    }

    AutoPtr<IIntentFilter> offFilter;
    CIntentFilter::New(IIntent::ACTION_SCREEN_OFF, (IIntentFilter**)&offFilter);
    offFilter->AddAction(IIntent::ACTION_USER_PRESENT);
    AutoPtr<IActivity> activity;
    GetActivity((IActivity**)&activity);
    AutoPtr<IIntent> resIntent;
    IContext::Probe(activity)->RegisterReceiver(mScreenOffReceiver, offFilter, (IIntent**)&resIntent);
    return NOERROR;
}
Ejemplo n.º 10
0
// Runs on the handler.
void WifiDisplayAdapter::HandleUpdateNotification()
{
    Boolean isConnected;
    {
        AutoLock lock(GetSyncRoot());

        if (!mPendingNotificationUpdate) {
            return;
        }

        mPendingNotificationUpdate = FALSE;
        isConnected = (mDisplayDevice != NULL);
    }

    AutoPtr<IUserHandle> all;
    AutoPtr<IUserHandleHelper> helper;
    CUserHandleHelper::AcquireSingleton((IUserHandleHelper**)&helper);
    helper->GetALL((IUserHandle**)&all);

    // Cancel the old notification if there is one.
    String nullStr;
    mNotificationManager->CancelAsUser(nullStr,
        R::string::wifi_display_notification_title, all);

    if (isConnected) {
        AutoPtr<IContext> context = GetContext();

        AutoPtr<IPendingIntentHelper> piHelper;
        CPendingIntentHelper::AcquireSingleton((IPendingIntentHelper**)&piHelper);

        AutoPtr<IUserHandle> current;
        helper->GetCURRENT((IUserHandle**)&current);

        // Initialize pending intents for the notification outside of the lock because
        // creating a pending intent requires a call into the activity manager.
        if (mSettingsPendingIntent == NULL) {
            AutoPtr<IIntent> settingsIntent;
            CIntent::New(ISettings::ACTION_WIFI_DISPLAY_SETTINGS, (IIntent**)&settingsIntent);
            settingsIntent->SetFlags(IIntent::FLAG_ACTIVITY_NEW_TASK
               | IIntent::FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
               | IIntent::FLAG_ACTIVITY_CLEAR_TOP);
            piHelper->GetActivityAsUser(
               context, 0, settingsIntent, 0, NULL, current,
               (IPendingIntent**)&mSettingsPendingIntent);
        }

        if (mDisconnectPendingIntent == NULL) {
            AutoPtr<IIntent> disconnectIntent;
            CIntent::New(ACTION_DISCONNECT, (IIntent**)&disconnectIntent);
            piHelper->GetBroadcastAsUser(
                context, 0, disconnectIntent, 0, current,
                (IPendingIntent**)&mDisconnectPendingIntent);
        }

        // Post the notification.
        AutoPtr<IResources> r;
        context->GetResources((IResources**)&r);
        AutoPtr<INotification> notification;
        AutoPtr<INotificationBuilder> builder;
        CNotificationBuilder::New(context, (INotificationBuilder**)&builder);
        String str;
        r->GetString(R::string::wifi_display_notification_title, &str);
        AutoPtr<ICharSequence> seq;
        CStringWrapper::New(str, (ICharSequence**)&seq);
        builder->SetContentTitle(seq);
        r->GetString(R::string::wifi_display_notification_message, &str);
        seq = NULL;
        CStringWrapper::New(str, (ICharSequence**)&seq);
        builder->SetContentText(seq);
        builder->SetContentIntent(mSettingsPendingIntent);
        builder->SetSmallIcon(R::drawable::ic_notify_wifidisplay);
        builder->SetOngoing(TRUE);
        r->GetString(R::string::wifi_display_notification_disconnect, &str);
        seq = NULL;
        CStringWrapper::New(str, (ICharSequence**)&seq);
        builder->AddAction(R::drawable::ic_menu_close_clear_cancel,
            seq, mDisconnectPendingIntent);
        builder->Build((INotification**)&notification);
        mNotificationManager->NotifyAsUser(nullStr,
            R::string::wifi_display_notification_title,
            notification, all);
    }
}