/*
 * Copyright 2012-2014 One Platform Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onepf.opfpush;

import android.content.Context;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;

/**
 * Base class for create {@code PushProvider}.
 *
 * @author Kirill Rozov
 * @since 05.09.14
 */
public abstract class BasePushProvider implements PushProvider {

    @NonNull
    private final Context mAppContext;

    @NonNull
    private final String mName;

    @NonNull
    private final String mHostAppPackage;

    /**
     * Base constructor for subclass.
     *
     * @param context        Any instance of {@code Context}.
     * @param name           Provider name.
     * @param hostAppPackage Package of application that handle push message from server
     *                       and deliver it to applications.
     */
    protected BasePushProvider(@NonNull Context context,
                               @NonNull String name,
                               @NonNull String hostAppPackage) {
        mAppContext = context.getApplicationContext();
        mName = name;
        mHostAppPackage = hostAppPackage;
    }

    /**
     * Verify is manifest contains permission.
     *
     * @param ctx        Any instance of {@code Context}.
     * @param permission Permission for verify.
     */
    protected static boolean checkPermission(@NonNull Context ctx, @NonNull String permission) {
        switch (ctx.getPackageManager().checkPermission(permission, ctx.getPackageName())) {
            case PackageManager.PERMISSION_GRANTED:
                return true;

            default:
                throw new OPFPushException("Your manifest doesn't contain permission '"
                        + permission + ".' Check your AndroidManifest.xml.");
        }
    }

    /**
     * Get {@code Context} instance.
     */
    @NonNull
    protected Context getContext() {
        return mAppContext;
    }

    @Override
    public boolean isAvailable() {
        return PackageUtils.isInstalled(mAppContext, mHostAppPackage);
    }

    @Override
    public String toString() {
        return mName + "(hostAppPackage='" + mHostAppPackage + ')';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        BasePushProvider that = (BasePushProvider) o;
        return mName.equals(that.mName);
    }

    @Override
    public boolean checkManifest() {
        return checkPermission(mAppContext, android.Manifest.permission.INTERNET);
    }

    @Override
    public int hashCode() {
        return mName.hashCode();
    }

    @NonNull
    @Override
    public String getName() {
        return mName;
    }

    @Override
    public void onUnavailable() {
    }

    @NonNull
    @Override
    public String getHostAppPackage() {
        return mHostAppPackage;
    }

    @Override
    public void onRegistrationInvalid() {
    }
}

@@ -750,16 +750,60 @@
 NonNull;
+%0Aimport android.support.annotation.Nullable;
 %0A%0A/**%0A *
@@ -1062,29 +1062,16 @@
 mName;%0A%0A
-    @NonNull%0A
     priv
@@ -1559,33 +1559,24 @@
             
-@NonNull 
 String hostA
@@ -3419,38 +3419,39 @@
  %7B%0A    %7D%0A%0A    @N
-onN
 ull
+able
 %0A    @Override%0A 

Change host app package in BasePushProvider.