aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/etrax/image/Makefile
Commit message (Collapse)AuthorAgeFilesLines
* define a shared IMG_PREFIX variable used as a basename for image files, it ↵Nicolas Thill2010-04-121-4/+3
| | | | | | contains board & subtarget infos (if appropriate) allowing subtargets to share the same bin directory without overwriting each other's files git-svn-id: svn://svn.openwrt.org/openwrt/trunk@20834 3c298f89-4303-0410-b956-a3cf2f4a3e73
* [etrax] update zImage locationAndy Boyett2009-06-201-2/+2
| | | | git-svn-id: svn://svn.openwrt.org/openwrt/trunk@16521 3c298f89-4303-0410-b956-a3cf2f4a3e73
* etrax: dump to 2.6.29Claudio Mignanti2009-04-191-2/+2
| | | | git-svn-id: svn://svn.openwrt.org/openwrt/trunk@15260 3c298f89-4303-0410-b956-a3cf2f4a3e73
* bump etrax to .25John Crispin2008-05-031-20/+8
| | | | git-svn-id: svn://svn.openwrt.org/openwrt/trunk@11028 3c298f89-4303-0410-b956-a3cf2f4a3e73
* make the image filenames a bit shorterFelix Fietkau2007-11-101-2/+2
| | | | git-svn-id: svn://svn.openwrt.org/openwrt/trunk@9533 3c298f89-4303-0410-b956-a3cf2f4a3e73
* strip the kernel version suffix from target directories, except for brcm-2.4 ↵Felix Fietkau2007-09-061-0/+55
(the -2.4 will be included in the board name here). CONFIG_LINUX_<ver>_<board> becomes CONFIG_TARGET_<board>, same for profiles. git-svn-id: svn://svn.openwrt.org/openwrt/trunk@8653 3c298f89-4303-0410-b956-a3cf2f4a3e73
/a> 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
/*
 * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
 * Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.sufficientlysecure.keychain.ui.widget;

import android.annotation.TargetApi;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.beardedhen.androidbootstrap.BootstrapButton;

import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
    private UncachedSecretKey mKey;

    private EditorListener mEditorListener = null;

    private boolean mIsMasterKey;
    BootstrapButton mDeleteButton;
    TextView mAlgorithm;
    TextView mKeyId;
    TextView mCreationDate;
    BootstrapButton mExpiryDateButton;
    Calendar mCreatedDate;
    Calendar mExpiryDate;
    Calendar mOriginalExpiryDate = null;
    CheckBox mChkCertify;
    CheckBox mChkSign;
    CheckBox mChkEncrypt;
    CheckBox mChkAuthenticate;
    int mUsage;
    int mOriginalUsage;
    boolean mIsNewKey;

    private CheckBox.OnCheckedChangeListener mCheckChanged = new CheckBox.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mEditorListener != null) {
                mEditorListener.onEdited();
            }
        }
    };


    private int mDatePickerResultCount = 0;
    private DatePickerDialog.OnDateSetListener mExpiryDateSetListener =
            new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    // Note: Ignore results after the first one - android sends multiples.
                    if (mDatePickerResultCount++ == 0) {
                        GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
                        date.set(year, monthOfYear, dayOfMonth);
                        if (mOriginalExpiryDate != null) {
                            long numDays = (date.getTimeInMillis() / 86400000) -
                                    (mOriginalExpiryDate.getTimeInMillis() / 86400000);
                            if (numDays == 0) {
                                setExpiryDate(mOriginalExpiryDate);
                            } else {
                                setExpiryDate(date);
                            }
                        } else {
                            setExpiryDate(date);
                        }
                        if (mEditorListener != null) {
                            mEditorListener.onEdited();
                        }
                    }
                }
            };

    public KeyEditor(Context context) {
        super(context);
    }

    public KeyEditor(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        setDrawingCacheEnabled(true);
        setAlwaysDrawnWithCacheEnabled(true);

        mAlgorithm = (TextView) findViewById(R.id.algorithm);
        mKeyId = (TextView) findViewById(R.id.keyId);
        mCreationDate = (TextView) findViewById(R.id.creation);
        mExpiryDateButton = (BootstrapButton) findViewById(R.id.expiry);

        mDeleteButton = (BootstrapButton) findViewById(R.id.delete);
        mDeleteButton.setOnClickListener(this);
        mChkCertify = (CheckBox) findViewById(R.id.chkCertify);
        mChkCertify.setOnCheckedChangeListener(mCheckChanged);
        mChkSign = (CheckBox) findViewById(R.id.chkSign);
        mChkSign.setOnCheckedChangeListener(mCheckChanged);
        mChkEncrypt = (CheckBox) findViewById(R.id.chkEncrypt);
        mChkEncrypt.setOnCheckedChangeListener(mCheckChanged);
        mChkAuthenticate = (CheckBox) findViewById(R.id.chkAuthenticate);
        mChkAuthenticate.setOnCheckedChangeListener(mCheckChanged);

        setExpiryDate(null);

        mExpiryDateButton.setOnClickListener(new OnClickListener() {
            @TargetApi(11)
            public void onClick(View v) {
                Calendar expiryDate = mExpiryDate;
                if (expiryDate == null) {
                    expiryDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                }
                /*
                 * Using custom DatePickerDialog which overrides the setTitle because
                 * the DatePickerDialog title is buggy (unix warparound bug).
                 * See: https://code.google.com/p/android/issues/detail?id=49066
                 */
                DatePickerDialog dialog = new ExpiryDatePickerDialog(getContext(),
                        mExpiryDateSetListener, expiryDate.get(Calendar.YEAR), expiryDate.get(Calendar.MONTH),
                        expiryDate.get(Calendar.DAY_OF_MONTH));
                mDatePickerResultCount = 0;
                dialog.setCancelable(true);
                dialog.setButton(Dialog.BUTTON_NEGATIVE,
                        getContext().getString(R.string.btn_no_date),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Note: Ignore results after the first one - android sends multiples.
                                if (mDatePickerResultCount++ == 0) {
                                    setExpiryDate(null);
                                    if (mEditorListener != null) {
                                        mEditorListener.onEdited();
                                    }
                                }
                            }
                        });

                // setCalendarViewShown() is supported from API 11 onwards.
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                    // Hide calendarView in tablets because of the unix warparound bug.
                    dialog.getDatePicker().setCalendarViewShown(false);
                }
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {

                    // will crash with IllegalArgumentException if we set a min date
                    // that is not before expiry
                    if (mCreatedDate != null && mCreatedDate.before(expiryDate)) {
                        dialog.getDatePicker()
                                .setMinDate(
                                        mCreatedDate.getTime().getTime() + DateUtils.DAY_IN_MILLIS);
                    } else {
                        // When created date isn't available
                        dialog.getDatePicker().setMinDate(expiryDate.getTime().getTime() + DateUtils.DAY_IN_MILLIS);
                    }
                }

                dialog.show();
            }
        });

        super.onFinishInflate();
    }

    public void setCanBeEdited(boolean canBeEdited) {
        if (!canBeEdited) {
            mDeleteButton.setVisibility(View.INVISIBLE);
            mExpiryDateButton.setEnabled(false);
            mChkSign.setEnabled(false); //certify is always disabled
            mChkEncrypt.setEnabled(false);
            mChkAuthenticate.setEnabled(false);
        }
    }

    public void setValue(UncachedSecretKey key, boolean isMasterKey, int usage, boolean isNewKey) {
        mKey = key;

        mIsMasterKey = isMasterKey;
        if (mIsMasterKey) {
            mDeleteButton.setVisibility(View.INVISIBLE);
        }

        mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(getContext(), key.getAlgorithm()));
        String keyIdStr = PgpKeyHelper.convertKeyIdToHex(key.getKeyId());
        mKeyId.setText(keyIdStr);

        boolean isElGamalKey = (key.isElGamalEncrypt());
        boolean isDSAKey = (key.isDSA());
        if (isElGamalKey) {
            mChkSign.setVisibility(View.INVISIBLE);
            TableLayout table = (TableLayout) findViewById(R.id.table_keylayout);
            TableRow row = (TableRow) findViewById(R.id.row_sign);
            table.removeView(row);
        }
        if (isDSAKey) {
            mChkEncrypt.setVisibility(View.INVISIBLE);
            TableLayout table = (TableLayout) findViewById(R.id.table_keylayout);
            TableRow row = (TableRow) findViewById(R.id.row_encrypt);
            table.removeView(row);
        }
        if (!mIsMasterKey) {
            mChkCertify.setVisibility(View.INVISIBLE);
            TableLayout table = (TableLayout) findViewById(R.id.table_keylayout);
            TableRow row = (TableRow) findViewById(R.id.row_certify);
            table.removeView(row);
        } else {
            TextView mLabelUsage2 = (TextView) findViewById(R.id.label_usage2);
            mLabelUsage2.setVisibility(View.INVISIBLE);
        }

        mIsNewKey = isNewKey;
        if (isNewKey) {
            mUsage = usage;
            mChkCertify.setChecked(
                    (usage & UncachedSecretKey.CERTIFY_OTHER) == UncachedSecretKey.CERTIFY_OTHER);
            mChkSign.setChecked(
                    (usage & UncachedSecretKey.SIGN_DATA) == UncachedSecretKey.SIGN_DATA);
            mChkEncrypt.setChecked(
                    ((usage & UncachedSecretKey.ENCRYPT_COMMS) == UncachedSecretKey.ENCRYPT_COMMS) ||
                    ((usage & UncachedSecretKey.ENCRYPT_STORAGE) == UncachedSecretKey.ENCRYPT_STORAGE));
            mChkAuthenticate.setChecked(
                    (usage & UncachedSecretKey.AUTHENTICATION) == UncachedSecretKey.AUTHENTICATION);
        } else {
            mUsage = key.getKeyUsage();
            mOriginalUsage = mUsage;
            if (key.isMasterKey()) {
                mChkCertify.setChecked(key.canCertify());
            }
            mChkSign.setChecked(key.canSign());
            mChkEncrypt.setChecked(key.canEncrypt());
            mChkAuthenticate.setChecked(key.canAuthenticate());
        }

        {
            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            cal.setTime(key.getCreationTime());
            setCreatedDate(cal);
        }

        Date expiryDate = key.getExpiryTime();
        if (expiryDate == null) {
            setExpiryDate(null);
        } else {
            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            cal.setTime(expiryDate);
            setExpiryDate(cal);
            mOriginalExpiryDate = cal;
        }

    }

    public UncachedSecretKey getValue() {
        return mKey;
    }

    public void onClick(View v) {
        final ViewGroup parent = (ViewGroup) getParent();
        if (v == mDeleteButton) {
            parent.removeView(this);
            if (mEditorListener != null) {
                mEditorListener.onDeleted(this, mIsNewKey);
            }
        }
    }

    public void setEditorListener(EditorListener listener) {
        mEditorListener = listener;
    }

    private void setCreatedDate(Calendar date) {
        mCreatedDate = date;
        if (date == null) {
            mCreationDate.setText(getContext().getString(R.string.none));
        } else {
            mCreationDate.setText(DateFormat.getDateInstance().format(date.getTime()));
        }
    }

    private void setExpiryDate(Calendar date) {
        mExpiryDate = date;
        if (date == null) {
            mExpiryDateButton.setText(getContext().getString(R.string.none));
        } else {
            mExpiryDateButton.setText(DateFormat.getDateInstance().format(date.getTime()));
        }
    }

    public Calendar getExpiryDate() {
        return mExpiryDate;
    }

    public int getUsage() {
        mUsage = (mUsage & ~UncachedSecretKey.CERTIFY_OTHER) |
                (mChkCertify.isChecked() ? UncachedSecretKey.CERTIFY_OTHER : 0);
        mUsage = (mUsage & ~UncachedSecretKey.SIGN_DATA) |
                (mChkSign.isChecked() ? UncachedSecretKey.SIGN_DATA : 0);
        mUsage = (mUsage & ~UncachedSecretKey.ENCRYPT_COMMS) |
                (mChkEncrypt.isChecked() ? UncachedSecretKey.ENCRYPT_COMMS : 0);
        mUsage = (mUsage & ~UncachedSecretKey.ENCRYPT_STORAGE) |
                (mChkEncrypt.isChecked() ? UncachedSecretKey.ENCRYPT_STORAGE : 0);
        mUsage = (mUsage & ~UncachedSecretKey.AUTHENTICATION) |
                (mChkAuthenticate.isChecked() ? UncachedSecretKey.AUTHENTICATION : 0);

        return mUsage;
    }

    public boolean needsSaving() {
        if (mIsNewKey) {
            return true;
        }

        boolean retval = (getUsage() != mOriginalUsage);

        boolean dateChanged;
        boolean mOEDNull = (mOriginalExpiryDate == null);
        boolean mEDNull = (mExpiryDate == null);
        if (mOEDNull != mEDNull) {
            dateChanged = true;
        } else {
            if (mOEDNull) {
                //both null, no change
                dateChanged = false;
            } else {
                dateChanged = ((mExpiryDate.compareTo(mOriginalExpiryDate)) != 0);
            }
        }
        retval |= dateChanged;

        return retval;
    }

    public boolean getIsNewKey() {
        return mIsNewKey;
    }
}

class ExpiryDatePickerDialog extends DatePickerDialog {

    public ExpiryDatePickerDialog(Context context, OnDateSetListener callBack,
                                  int year, int monthOfYear, int dayOfMonth) {
        super(context, callBack, year, monthOfYear, dayOfMonth);
    }

    //Set permanent title.
    public void setTitle(CharSequence title) {
        super.setTitle(getContext().getString(R.string.expiry_date_dialog_title));
    }
}